-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor : 메인페이지 공연 정렬 순서 변경 #567
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,22 +51,47 @@ public Slice<Event> querySliceEventsByStatus(EventStatus status, Pageable pageab | |
|
||
@Override | ||
public Slice<Event> querySliceEventsByKeyword(String keyword, Pageable pageable) { | ||
List<Event> events = | ||
List<Event> openEvents = | ||
queryFactory | ||
.selectFrom(event) | ||
.where(eqStatusCanExposed(), nameContains(keyword)) | ||
.orderBy(statusDesc(), startAtAsc()) | ||
.where(eqStatusOpen().and(nameContains(keyword))) | ||
.orderBy(createdAtAsc()) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize() + 1) | ||
.fetch(); | ||
return SliceUtil.valueOf(events, pageable); | ||
|
||
final long remainingSize = Math.max(pageable.getPageSize() - openEvents.size(), 0); | ||
if (remainingSize > 0) { | ||
openEvents.addAll(queryClosedEventsByKeywordAndSize(keyword, pageable, remainingSize)); | ||
} | ||
Comment on lines
+63
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이 로직은 무슨역할이죵 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정렬 순서가 앞 뒤로 달라서 어쩔 수 없이 쿼리를 두번 쏴서 페이징하는데 근데 이미 OPEN 공연을 pageSize 만큼 전부 가져왔을 수도 있으니 |
||
return SliceUtil.valueOf(openEvents, pageable); | ||
} | ||
|
||
@Override | ||
public List<Event> queryEventsByEndAtBeforeAndStatusOpen(LocalDateTime time) { | ||
return queryFactory.selectFrom(event).where(endAtBefore(time), statusEq(OPEN)).fetch(); | ||
} | ||
|
||
private List<Event> queryClosedEventsByKeywordAndSize( | ||
String keyword, Pageable pageable, Long size) { | ||
final long totalOpenEventsSize = queryCountByKeywordAndStatus(keyword, OPEN); | ||
final long closedEventsOffset = Math.max(pageable.getOffset() - totalOpenEventsSize, 0); | ||
return queryFactory | ||
.selectFrom(event) | ||
.where(eqStatusClosed().and(nameContains(keyword))) | ||
.orderBy(startAtDesc()) | ||
.offset(closedEventsOffset) | ||
.limit(size + 1) | ||
.fetch(); | ||
} | ||
|
||
private long queryCountByKeywordAndStatus(String keyword, EventStatus status) { | ||
return queryFactory | ||
.from(event) | ||
.where(statusEq(status).and(nameContains(keyword))) | ||
.fetchCount(); | ||
} | ||
|
||
private BooleanExpression hostIdIn(List<Long> hostId) { | ||
return event.hostId.in(hostId); | ||
} | ||
|
@@ -75,18 +100,14 @@ private BooleanExpression eqStatusOpen() { | |
return event.status.eq(OPEN); | ||
} | ||
|
||
private BooleanExpression eqStatusCanExposed() { | ||
return event.status.eq(OPEN).or(event.status.eq(CLOSED)); | ||
private BooleanExpression eqStatusClosed() { | ||
return event.status.eq(CLOSED); | ||
} | ||
|
||
private BooleanExpression statusEq(EventStatus status) { | ||
return event.status.eq(status); | ||
} | ||
|
||
private BooleanExpression statusNotEq(EventStatus status) { | ||
return event.status.eq(status).not(); | ||
} | ||
|
||
private BooleanExpression nameContains(String keyword) { | ||
return keyword == null ? null : event.eventBasic.name.containsIgnoreCase(keyword); | ||
} | ||
|
@@ -95,10 +116,18 @@ private OrderSpecifier<LocalDateTime> createdAtDesc() { | |
return event.createdAt.desc(); | ||
} | ||
|
||
private OrderSpecifier<LocalDateTime> createdAtAsc() { | ||
return event.createdAt.asc(); | ||
} | ||
|
||
private OrderSpecifier<LocalDateTime> startAtAsc() { | ||
return event.eventBasic.startAt.asc(); | ||
} | ||
|
||
private OrderSpecifier<LocalDateTime> startAtDesc() { | ||
return event.eventBasic.startAt.desc(); | ||
} | ||
|
||
private OrderSpecifier<EventStatus> statusDesc() { | ||
return event.status.desc(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and로 묶어주는것도 좋네용