Skip to content
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
Expand Up @@ -48,7 +48,8 @@
public interface ClubApi {

@Operation(summary = "페이지 네이션으로 동아리 리스트를 조회한다.", description = """
- isRecruiting가 true일 경우, 모집일이 빠른 순으로 정렬됩니다.
- isRecruiting가 true일 경우, 모집 중인 동아리만 조회하며 모집일(마감일)이 빠른 순으로 정렬됩니다.
- isRecruiting가 false일 경우, 전체 동아리를 조회하되 모집 중인 동아리를 먼저 보여줍니다.
- status은 BEFORE(모집 전), ONGOING(모집 중), CLOSED(모집 마감)으로 반환됩니다.
""")
@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;

Expand Down Expand Up @@ -138,10 +140,16 @@ private void addRecruitingCondition(BooleanBuilder condition, Boolean isRecruiti
return;
}

condition.and(createOngoingRecruitmentCondition());
}

private BooleanExpression createOngoingRecruitmentCondition() {
LocalDate today = LocalDate.now();
condition.and(clubRecruitment.id.isNotNull())
.and(clubRecruitment.startDate.loe(today))
.and(clubRecruitment.endDate.goe(today));
return clubRecruitment.id.isNotNull()
.and(
clubRecruitment.isAlwaysRecruiting.isTrue()
.or(clubRecruitment.startDate.loe(today).and(clubRecruitment.endDate.goe(today)))
);
}

/* 정렬 조건 */
Expand All @@ -155,11 +163,33 @@ private List<OrderSpecifier<?>> createClubSortOrders(Boolean isRecruiting) {
}

private void addRecruitmentSortOrder(List<OrderSpecifier<?>> orders, Boolean isRecruiting) {
BooleanExpression isOngoingRecruitment = createOngoingRecruitmentCondition();

if (!isRecruiting) {
return;
orders.add(
new CaseBuilder()
.when(isOngoingRecruitment)
.then(0)
.otherwise(1)
.asc()
);
}

orders.add(clubRecruitment.endDate.asc());
orders.add(
new CaseBuilder()
.when(isOngoingRecruitment.and(clubRecruitment.endDate.isNull()))
.then(1)
.otherwise(0)
.asc()
);

orders.add(
new CaseBuilder()
.when(isOngoingRecruitment)
.then(clubRecruitment.endDate)
.otherwise((LocalDate)null)
.asc()
);
}

private void addDefaultSortOrder(List<OrderSpecifier<?>> orders) {
Expand Down
Loading