Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NABI-205--refactor : suggestionInfo, cardInfo 명시 #33

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.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
Loading