Skip to content

Commit

Permalink
fix: 공고 목록 조회 api 정렬 조건 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kikingki committed Sep 23, 2024
1 parent d8bf570 commit 88d9883
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,31 @@ public OrderSpecifier<?>[] getOrderSpecifiers(Sort sort) {
List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>();

for (Sort.Order order : sort) {
OrderSpecifier<?> orderSpecifier = null;
OrderSpecifier<?> idSort = null;

LocalDate currentDate = LocalDate.now();

OrderSpecifier<?> prioritySort = new OrderSpecifier<>(
Order.DESC,
Expressions.booleanTemplate("CASE WHEN {0} >= {1} THEN 1 ELSE 0 END",
infoPost.recruitmentEndDate, currentDate)
);

orderSpecifiers.add(prioritySort);

switch (order.getProperty()) {
case "latest":
orderSpecifier = new OrderSpecifier<>(Order.DESC, infoPost.id);
idSort = new OrderSpecifier<>(Order.DESC, infoPost.id);
orderSpecifiers.add(idSort);
break;
case "deadline":
// recruitmentEndDate가 현재 날짜보다 크거나 같은 게시글을 먼저 정렬
LocalDate currentDate = LocalDate.now();

// 정렬 기준 추가: 현재 날짜보다 크거나 같은 날짜는 우선순위가 높음
OrderSpecifier<?> prioritySort = new OrderSpecifier<>(
Order.DESC,
Expressions.booleanTemplate("CASE WHEN {0} >= {1} THEN 1 ELSE 0 END",
infoPost.recruitmentEndDate, currentDate)
);

// 기본 정렬: recruitmentEndDate 내림차순
OrderSpecifier<?> dateSort = new OrderSpecifier<>(Order.DESC, infoPost.recruitmentEndDate);

// 두 개의 정렬 기준을 조합
orderSpecifiers.add(prioritySort);
OrderSpecifier<?> dateSort = new OrderSpecifier<>(Order.ASC, infoPost.recruitmentEndDate);
orderSpecifiers.add(dateSort);
break;
}

if (orderSpecifier != null) {
orderSpecifiers.add(orderSpecifier);
if (idSort != null) {
orderSpecifiers.add(idSort);
}
}

Expand Down

0 comments on commit 88d9883

Please sign in to comment.