From 0c7ac5427c3bd6950ae0dac459182c77782b488b Mon Sep 17 00:00:00 2001 From: born-A <93516595+born-A@users.noreply.github.com> Date: Tue, 14 Nov 2023 01:51:50 +0900 Subject: [PATCH] =?UTF-8?q?NABI-205--refactor=20:=20suggestionInfo,=20card?= =?UTF-8?q?Info=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CardReadResponseDTO.java | 13 ++++++++ .../response/SuggestionDetailResponseDTO.java | 18 ++++++++++ .../SuggestionListReadResponseDTO.java | 27 ++------------- .../repository/SuggestionRepositoryImpl.java | 33 ++++++++++++------- .../suggestion/service/SuggestionService.java | 9 ++--- 5 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 src/main/java/org/prgrms/nabimarketbe/domain/card/dto/response/CardReadResponseDTO.java create mode 100644 src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionDetailResponseDTO.java diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/dto/response/CardReadResponseDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/dto/response/CardReadResponseDTO.java new file mode 100644 index 00000000..f5bb0988 --- /dev/null +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/dto/response/CardReadResponseDTO.java @@ -0,0 +1,13 @@ +package org.prgrms.nabimarketbe.domain.card.dto.response; + +import lombok.Getter; +import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; + +@Getter +public class CardReadResponseDTO { + private Long cardId; + private String cardTitle; + private String itemName; + private PriceRange priceRange; + private String thumbnail; +} diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionDetailResponseDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionDetailResponseDTO.java new file mode 100644 index 00000000..491985f7 --- /dev/null +++ b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionDetailResponseDTO.java @@ -0,0 +1,18 @@ +package org.prgrms.nabimarketbe.domain.suggestion.dto.response; + +import lombok.Getter; +import org.prgrms.nabimarketbe.domain.suggestion.entity.DirectionType; +import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionStatus; +import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; + +import java.time.LocalDateTime; + +@Getter +public class SuggestionDetailResponseDTO { + private Long suggestionId; + private SuggestionType suggestionType; + private SuggestionStatus suggestionStatus; + private LocalDateTime createdAt; + private LocalDateTime modifiedAt; + private DirectionType directionType; +} diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionListReadResponseDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionListReadResponseDTO.java index 471b1ae2..24184fa5 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionListReadResponseDTO.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionListReadResponseDTO.java @@ -2,32 +2,11 @@ import lombok.Getter; -import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; -import org.prgrms.nabimarketbe.domain.suggestion.entity.DirectionType; -import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionStatus; -import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; - -import java.time.LocalDateTime; +import org.prgrms.nabimarketbe.domain.card.dto.response.CardReadResponseDTO; @Getter public class SuggestionListReadResponseDTO{ - private Long suggestionId; - - private Long cardId; - - private String cardTitle; - - private String itemName; - - private PriceRange priceRange; - - private String thumbnail; - - private SuggestionType suggestionType; - - private SuggestionStatus suggestionStatus; - - private LocalDateTime createdAt; + private CardReadResponseDTO cardInfo; - private DirectionType directionType; + private SuggestionDetailResponseDTO suggestionInfo; } diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/repository/SuggestionRepositoryImpl.java b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/repository/SuggestionRepositoryImpl.java index a8b59e44..4a639858 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/repository/SuggestionRepositoryImpl.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/repository/SuggestionRepositoryImpl.java @@ -10,7 +10,9 @@ import lombok.RequiredArgsConstructor; +import org.prgrms.nabimarketbe.domain.card.dto.response.CardReadResponseDTO; import org.prgrms.nabimarketbe.domain.card.entity.QCard; +import org.prgrms.nabimarketbe.domain.suggestion.dto.response.SuggestionDetailResponseDTO; import org.prgrms.nabimarketbe.domain.suggestion.dto.response.SuggestionListReadPagingResponseDTO; import org.prgrms.nabimarketbe.domain.suggestion.dto.response.SuggestionListReadResponseDTO; import org.prgrms.nabimarketbe.domain.suggestion.entity.DirectionType; @@ -39,16 +41,23 @@ public SuggestionListReadPagingResponseDTO getSuggestionsByType( .select( Projections.fields( SuggestionListReadResponseDTO.class, - suggestion.suggestionId, - getQCardCounter(directionType).cardId, - getQCardCounter(directionType).cardTitle, - getQCardCounter(directionType).item.itemName, - getQCardCounter(directionType).item.priceRange, - getQCardCounter(directionType).thumbNailImage.as("thumbnail"), - suggestion.suggestionType, - suggestion.suggestionStatus, - suggestion.createdDate.as("createdAt"), - Expressions.as(Expressions.constant(directionType),"directionType") + Projections.fields( + CardReadResponseDTO.class, + getQCardCounter(directionType).cardId, + getQCardCounter(directionType).cardTitle, + getQCardCounter(directionType).item.itemName, + getQCardCounter(directionType).item.priceRange, + getQCardCounter(directionType).thumbNailImage.as("thumbnail") + ).as("cardInfo"), + Projections.fields( + SuggestionDetailResponseDTO.class, + suggestion.suggestionId, + suggestion.suggestionType, + suggestion.suggestionStatus, + suggestion.createdDate.as("createdAt"), + suggestion.modifiedDate.as("modifiedAt"), + Expressions.as(Expressions.constant(directionType),"directionType") + ).as("suggestionInfo") ) ) .from(suggestion) @@ -101,11 +110,11 @@ private BooleanExpression cursorIdLessThan(String cursorId) { * 커서 id 생성 */ private String createCursorId(SuggestionListReadResponseDTO suggestionListReadResponseDTO) { - return suggestionListReadResponseDTO.getCreatedAt().toString() + return suggestionListReadResponseDTO.getSuggestionInfo().getCreatedAt().toString() .replace("T", "") .replace("-", "") .replace(":", "") - + String.format("%08d", suggestionListReadResponseDTO.getSuggestionId()); + + String.format("%08d", suggestionListReadResponseDTO.getSuggestionInfo().getSuggestionId()); } /** diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/service/SuggestionService.java b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/service/SuggestionService.java index 78fbc820..c82eb7a0 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/service/SuggestionService.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/suggestion/service/SuggestionService.java @@ -65,12 +65,13 @@ public SuggestionListReadPagingResponseDTO getSuggestionsByType( String cursorId, Integer size ){ - User user = userRepository.findById(checkService.parseToken(token)) - .orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND)); - - Card card = cardRepository.findByCardIdAndUser(cardId, user) + Card card = cardRepository.findById(cardId) .orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_MATCHED)); + if (!checkService.isEqual(token, card.getUser().getUserId())) { + throw new BaseException(ErrorCode.USER_NOT_MATCHED); + } + return suggestionRepository.getSuggestionsByType( directionType, suggestionType,