Skip to content

Commit

Permalink
NABI-205--refactor : suggestionInfo, cardInfo 명시
Browse files Browse the repository at this point in the history
  • Loading branch information
born-A committed Nov 13, 2023
1 parent 38f557b commit 0c7ac54
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0c7ac54

Please sign in to comment.