Skip to content

Commit

Permalink
Merge pull request #16 from 2023-CMC-Hackerthon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AlmondBreez3 authored Nov 25, 2023
2 parents 126f252 + a0ce596 commit edbac5d
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ public ResponseEntity<?> createCard(@RequestBody CardCreateRequestDto cardCreate
}


@PatchMapping("/cards/{cardId}/delete")
public ResponseEntity<?> deleteCard(@PathVariable Long cardId) {
return cardService.deleteCard(cardId);
}

@GetMapping("cards/{cardId}")
public ResponseEntity<?> getCardInfo(@PathVariable Long cardId) {
return cardService.getCardInfo(cardId);
}

@Operation(description = "명함")
@PostMapping(value = "/image", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public SuccessResponse<Object> uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
@PostMapping(value = "/image/{walletId}", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public SuccessResponse<Object> uploadImage(@RequestParam("file") MultipartFile file, Long walletId) throws IOException {
try {
String imageUrl = cardService.uploadImage(file);
String imageUrl = cardService.uploadImage(file, walletId);
SuccessResponse<Object> successResponse = SuccessResponse.onSuccess(200,imageUrl);
return successResponse;
} catch (IOException e) {
throw new IllegalArgumentException("오류");
}
}

@PatchMapping("/cards/{cardId}/delete")
public ResponseEntity<?> deleteCard(@PathVariable Long cardId) {
return cardService.deleteCard(cardId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.hackathon.hackathon.domain.card.dto.response;

import com.hackathon.hackathon.domain.card.enums.Gender;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -13,11 +16,31 @@ public class CardCreateResponseDto {
private Long id;

@NotNull
private String name;
private String nickname;

private String contact;

@Enumerated(EnumType.STRING)
private Gender gender;

private String instagramId;

private String blogUrl;

private String youtubeUrl;

private String githubId;

@Builder
public CardCreateResponseDto(Long id, String name) {
public CardCreateResponseDto(Long id, String nickname, String contact, Gender gender, String instagramId,
String blogUrl, String youtubeUrl, String githubId) {
this.id = id;
this.name = name;
this.nickname = nickname;
this.contact = contact;
this.gender = gender;
this.instagramId = instagramId;
this.blogUrl = blogUrl;
this.youtubeUrl = youtubeUrl;
this.githubId = githubId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.hackathon.hackathon.domain.card.dto.response.CardDeleteResponseDto;
import com.hackathon.hackathon.domain.card.entity.Card;
import com.hackathon.hackathon.domain.card.repository.CardRepository;
import com.hackathon.hackathon.domain.wallet.entity.Wallet;
import com.hackathon.hackathon.domain.wallet.repository.WalletRepository;
import com.hackathon.hackathon.domain.wallet.service.WalletService;
import com.hackathon.hackathon.global.S3.S3Service;
import com.hackathon.hackathon.global.response.SuccessResponse;
import java.io.IOException;
Expand All @@ -26,6 +28,7 @@ public class CardService {

private final CardRepository cardRepository;
private final WalletRepository walletRepository;
private final WalletService walletService;
private final S3Service s3Service;

@Transactional
Expand All @@ -42,20 +45,30 @@ public ResponseEntity<?> createCard(CardCreateRequestDto cardCreateRequestDto, L
wallet(walletRepository.findById(walletId).orElse(null)).
build();
Card saveCard = cardRepository.save(card);
Long saveId = saveCard.getId();
String saveNickname = saveCard.getNickname();

SuccessResponse apiResponse = getSuccessResponse(saveCard);

return ResponseEntity.ok(apiResponse);
}

private static SuccessResponse getSuccessResponse(Card saveCard) {
CardCreateResponseDto cardCreateResponseDto = CardCreateResponseDto.builder().
id(saveId).
name(saveNickname).
id(saveCard.getId()).
nickname(saveCard.getNickname()).
contact(saveCard.getContact()).
gender(saveCard.getGender()).
instagramId(saveCard.getInstagramId()).
blogUrl(saveCard.getBlogUrl()).
youtubeUrl(saveCard.getYoutubeUrl()).
githubId(saveCard.getGithubId()).
build();

SuccessResponse apiResponse = SuccessResponse.builder().
code(200).
message("카드 생성에 성공했습니다.").
data(cardCreateResponseDto).
build();

return ResponseEntity.ok(apiResponse);
return apiResponse;
}

@Transactional
Expand All @@ -77,8 +90,33 @@ public ResponseEntity<?> deleteCard(Long cardId) {
return ResponseEntity.ok(apiResponse);
}

public String uploadImage(MultipartFile file) throws IOException {
public ResponseEntity<?> getCardInfo(Long cardId) {
Optional<Card> findCard = cardRepository.findById(cardId);
CardCreateResponseDto cardCreateResponseDto = CardCreateResponseDto.builder().
id(findCard.get().getId()).
nickname(findCard.get().getNickname()).
contact(findCard.get().getContact()).
gender(findCard.get().getGender()).
instagramId(findCard.get().getInstagramId()).
blogUrl(findCard.get().getBlogUrl()).
youtubeUrl(findCard.get().getYoutubeUrl()).
githubId(findCard.get().getGithubId()).
build();

SuccessResponse apiResponse = SuccessResponse.builder().
code(200).
message("카드 생성에 성공했습니다.").
data(cardCreateResponseDto).
build();

return ResponseEntity.ok(apiResponse);
}

@Transactional
public String uploadImage(MultipartFile file, Long walletId) throws IOException {
String imageUrl = s3Service.upload(file);
Wallet wallet = walletRepository.findById(walletId).get();
wallet.addImageUrl(imageUrl);
return imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/wallets")
Expand Down Expand Up @@ -47,6 +49,19 @@ public SuccessResponse<Object> deleteWallet(@RequestParam Long walletId){
return walletService.deleteWallet(user, walletId);
}

@Operation(description = "내가 만든 카드들(이미지) 지갑별로 보기")
@GetMapping("/cards/{walletId}")
public SuccessResponse<Object> getCardUrls(@RequestParam Long walletId){
User user = authentiatedUserUtils.getCurrentUser();
return walletService.getAllCardLinks(walletId);
}

// @Operation(description = "지갑에 여러 이미지 url 올리기")
// @PostMapping("/{walletId}")
// public List<String> uploadCard(@RequestParam Long walletId) {
//
// }




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Entity
@Builder
@AllArgsConstructor
Expand All @@ -24,6 +26,10 @@ public class Wallet extends BaseTimeEntity {
private User user;
@Enumerated(EnumType.STRING)
protected WalletStatus status;

@ElementCollection
private List<String> imageUrls;

public Wallet() {
// 기본 생성자
this.status = WalletStatus.ACTIVE; // 생성자에서도 ACTIVE로 초기화
Expand All @@ -35,4 +41,8 @@ public void updateStatus(WalletStatus newStatus) {
this.status = newStatus;
}

@Transactional
public void addImageUrl(String imageUrl) {
this.imageUrls.add(imageUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hackathon.hackathon.domain.wallet.dto.request.WalletRequestDTO;
import com.hackathon.hackathon.domain.wallet.dto.response.WalletResponseDTO;
import com.hackathon.hackathon.domain.wallet.entity.Wallet;
import com.hackathon.hackathon.domain.wallet.enums.WalletStatus;
import com.hackathon.hackathon.domain.wallet.repository.WalletRepository;
import com.hackathon.hackathon.global.response.SuccessResponse;
import com.hackathon.hackathon.global.utils.AuthentiatedUserUtils;
Expand All @@ -16,6 +17,7 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.hackathon.hackathon.domain.wallet.enums.WalletStatus.ACTIVE;
import static com.hackathon.hackathon.domain.wallet.enums.WalletStatus.DEACTIVE;
Expand Down Expand Up @@ -60,7 +62,11 @@ public SuccessResponse<Object> getWallet(User user, Long walletId) {

public SuccessResponse<Object> getWallets(User user) {
List<Wallet> wallets = walletRepository.findAllByUserId(user.getId());
return SuccessResponse.onSuccess(200,wallets);
// status가 ACTIVE인 Wallet만 필터링
List<Wallet> activeWallets = wallets.stream()
.filter(wallet -> WalletStatus.ACTIVE.equals(wallet.getStatus()))
.collect(Collectors.toList());
return SuccessResponse.onSuccess(200,activeWallets);
}


Expand All @@ -78,4 +84,11 @@ private Wallet updateWalletStatus(Wallet wallet){
walletRepository.save(wallet);
return wallet;
}

public SuccessResponse<Object> getAllCardLinks(Long walletId) {
Wallet wallet = walletRepository.findById(walletId).get();
List<String> wallets = wallet.getImageUrls();
return SuccessResponse.onSuccess(200,wallets);
}

}

0 comments on commit edbac5d

Please sign in to comment.