Skip to content

Commit

Permalink
NABI-125--refactor : 메서드명 변경, 주석 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
born-A committed Nov 9, 2023
1 parent fabd1a0 commit 732d1b0
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ public SuggestionListReadPagingResponseDTO getSuggestionsByType(
Projections.fields(
SuggestionListReadResponseDTO.class,
suggestion.suggestionId,
getCounter(directionType).cardId,
getCounter(directionType).cardTitle,
getCounter(directionType).item.itemName,
getCounter(directionType).item.priceRange,
getCounter(directionType).thumbNailImage.as("thumbnail"),
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")
)
)
.from(suggestion)
.join(getJoin(directionType),card)
.on(getOn(directionType,cardId))
.join(getQcardByDirectionType(directionType),card)
.on(getExpressionByDirectionType(directionType,cardId))
.where(cursorIdLessThan(cursorId), suggestionTypeEquals(suggestionType))
.orderBy(suggestion.createdDate.desc())
.limit(size)
Expand All @@ -65,6 +65,9 @@ public SuggestionListReadPagingResponseDTO getSuggestionsByType(
return new SuggestionListReadPagingResponseDTO(suggestionList1, nextCursor);
}

/**
* 오퍼, 찔러보기 필터링
*/
private BooleanExpression suggestionTypeEquals(SuggestionType suggestionType) {
if (suggestionType == null) {
throw new BaseException(ErrorCode.INVALID_REQUEST);
Expand All @@ -73,6 +76,9 @@ private BooleanExpression suggestionTypeEquals(SuggestionType suggestionType) {
return suggestion.suggestionType.eq(suggestionType);
}

/**
* 커스텀 커서 id가 주어진 cursorId보다 작은지 확인
*/
private BooleanExpression cursorIdLessThan(String cursorId) {
if (cursorId == null) {
return null;
Expand All @@ -91,28 +97,43 @@ private BooleanExpression cursorIdLessThan(String cursorId) {
)).lt(cursorId);
}

/**
* 커서 id 생성
*/
private String createCursorId(SuggestionListReadResponseDTO suggestionListReadResponseDTO) {
return suggestionListReadResponseDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬
return suggestionListReadResponseDTO.getCreatedAt().toString()
.replace("T", "")
.replace("-", "")
.replace(":", "")
+ String.format("%08d", suggestionListReadResponseDTO.getSuggestionId());
}

private QCard getJoin(DirectionType directionType) {
/**
* 내 카드의 대상이 받은 / 보낸 제안인지에 따른 join 절 분기문 처리
*/
private QCard getQcardByDirectionType(DirectionType directionType) {
return switch (directionType) {
case RECEIVE -> suggestion.toCard;
case SEND -> suggestion.fromCard;
};
}
private QCard getCounter(DirectionType directionType) {

/**
* 받은 / 보낸 제안인지에 따른 Projections.fields 분기문 처리
* 내가 받은 제안 조회 -> fromCard 필드
* 내가 보낸 제안 -> toCard 필드
*/
private QCard getQCardCounter(DirectionType directionType) {
return switch (directionType) {
case RECEIVE -> suggestion.fromCard;
case SEND -> suggestion.toCard;
};
}

private BooleanExpression getOn(
/**
* 받은 / 보낸 제안인지에 따른 on 절 분기문 처리
*/
private BooleanExpression getExpressionByDirectionType(
DirectionType directionType,
Long cardId
) {
Expand Down

0 comments on commit 732d1b0

Please sign in to comment.