diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java index 76b5ef60..4af39640 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java @@ -29,7 +29,7 @@ public Slice querySliceEventsByHostIdIn(List hostIds, Pageable page queryFactory .selectFrom(event) .where(hostIdIn(hostIds)) - .orderBy(event.id.desc()) + .orderBy(statusDesc(), createdAtDesc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize() + 1) .fetch(); @@ -41,8 +41,8 @@ public Slice querySliceEventsByStatus(EventStatus status, Pageable pageab List events = queryFactory .selectFrom(event) - .where(eqStatusOpen()) - .orderBy(createdAtDesc()) + .where(statusEq(status)) + .orderBy(statusDesc(), startAtAsc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize() + 1) .fetch(); @@ -54,8 +54,8 @@ public Slice querySliceEventsByKeyword(String keyword, Pageable pageable) List events = queryFactory .selectFrom(event) - .where(eqStatusOpen().and(nameContains(keyword))) - .orderBy(createdAtDesc()) + .where(nameContains(keyword)) + .orderBy(statusDesc(), startAtAsc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize() + 1) .fetch(); @@ -75,6 +75,10 @@ private BooleanExpression eqStatusOpen() { return event.status.eq(OPEN); } + private BooleanExpression statusEq(EventStatus status) { + return event.status.eq(status); + } + private BooleanExpression notEqClosed() { return event.status.eq(CLOSED).not(); } @@ -87,6 +91,14 @@ private OrderSpecifier createdAtDesc() { return event.createdAt.desc(); } + private OrderSpecifier startAtAsc() { + return event.eventBasic.startAt.asc(); + } + + private OrderSpecifier statusDesc() { + return event.status.desc(); + } + private BooleanExpression endAtBefore(LocalDateTime time) { DateTemplate eventEndAtTemplate = Expressions.dateTemplate(