Skip to content

Commit

Permalink
NABI-204--refactor : 카드업데이트 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BeommoKoo-dev committed Nov 14, 2023
1 parent c0b4b93 commit 4988b55
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CardResponseDTO<CardCreateResponseDTO> createCard(

Card card = cardCreateRequestDTO.toCardEntity(item, user);

CardImage thumbNail = new CardImage(cardCreateRequestDTO.thumbNailImage(), card);
CardImage thumbnail = new CardImage(cardCreateRequestDTO.thumbnail(), card);

// images 비어있을 경우..
List<CardImage> images = Optional.ofNullable(cardCreateRequestDTO.images())
Expand All @@ -80,7 +80,7 @@ public CardResponseDTO<CardCreateResponseDTO> createCard(
.map(i -> i.toCardImageEntity(card))
.toList();

List<CardImage> newCardImages = addThumbNail(images, thumbNail);
List<CardImage> newCardImages = addThumbnail(images, thumbnail);

Item savedItem = itemRepository.save(item);
Card savedCard = cardRepository.save(card);
Expand Down Expand Up @@ -121,20 +121,26 @@ public CardResponseDTO<CardUpdateResponseDTO> updateCardById(

card.updateCard(
cardUpdateRequestDTO.cardTitle(),
cardUpdateRequestDTO.thumbNailImage(),
cardUpdateRequestDTO.poke(),
cardUpdateRequestDTO.thumbnail(),
cardUpdateRequestDTO.pokeAvailable(),
cardUpdateRequestDTO.content(),
cardUpdateRequestDTO.tradeType(),
cardUpdateRequestDTO.tradeArea()
);

cardImageRepository.deleteAllByCard(card);

List<CardImage> cardImages = cardUpdateRequestDTO.images().stream()
CardImage thumbnail = new CardImage(cardUpdateRequestDTO.thumbnail(), card);

List<CardImage> images = Optional.ofNullable(cardUpdateRequestDTO.images())
.orElse(new ArrayList<>())
.stream()
.map(i -> i.toCardImageEntity(card))
.toList();

List<CardImage> savedCardImages = cardImageRepository.saveAll(cardImages);
List<CardImage> newCardImages = addThumbnail(images, thumbnail);

List<CardImage> savedCardImages = cardImageRepository.saveAll(newCardImages);

CardUpdateResponseDTO cardUpdateResponseDTO = CardUpdateResponseDTO.of(
card,
Expand Down Expand Up @@ -277,7 +283,7 @@ public void deleteCardById(
cardRepository.delete(card);
}

private List<CardImage> addThumbNail(List<CardImage> cardImages, CardImage thumbnail) {
private List<CardImage> addThumbnail(List<CardImage> cardImages, CardImage thumbnail) {
List<CardImage> newCardImages = new ArrayList<>(cardImages);
newCardImages.add(0, thumbnail);

Expand Down

0 comments on commit 4988b55

Please sign in to comment.