From b69fdc5ad07eb7548e6f6cb831f0a526cd5a9a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=85=B8=EA=B2=BD=EB=AF=BC?= Date: Mon, 24 Jul 2023 23:57:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=9D=B8=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EA=B3=B5=EC=97=B0=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD=20(#567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : 메인페이지 쿼리 순서 변경 * chore : spotless apply --- .../repository/EventCustomRepositoryImpl.java | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) 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 950307f2..96cd4b01 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 @@ -51,15 +51,20 @@ public Slice querySliceEventsByStatus(EventStatus status, Pageable pageab @Override public Slice querySliceEventsByKeyword(String keyword, Pageable pageable) { - List events = + List 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)); + } + return SliceUtil.valueOf(openEvents, pageable); } @Override @@ -67,6 +72,26 @@ public List queryEventsByEndAtBeforeAndStatusOpen(LocalDateTime time) { return queryFactory.selectFrom(event).where(endAtBefore(time), statusEq(OPEN)).fetch(); } + private List 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 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 createdAtDesc() { return event.createdAt.desc(); } + private OrderSpecifier createdAtAsc() { + return event.createdAt.asc(); + } + private OrderSpecifier startAtAsc() { return event.eventBasic.startAt.asc(); } + private OrderSpecifier startAtDesc() { + return event.eventBasic.startAt.desc(); + } + private OrderSpecifier statusDesc() { return event.status.desc(); } From 7f8e8aa9039c08860edaf3721829c791fb5c45ab Mon Sep 17 00:00:00 2001 From: Chan Jin Date: Sun, 3 Mar 2024 21:56:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=97=90=EC=84=9C=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EA=B0=AF=EC=88=98=EC=99=80,=20=EC=BF=BC=EB=A6=AC=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EA=B0=AF=EC=88=98=EA=B0=80=20=EA=B0=99=EC=95=84?= =?UTF-8?q?=EB=8F=84,=20hasNext=20=EC=B2=B4=ED=81=AC=EB=A5=BC=20=ED=95=B4?= =?UTF-8?q?=EC=95=BC=ED=95=9C=EB=8B=A4=20(#569)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/event/repository/EventCustomRepositoryImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 96cd4b01..c96701e5 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 @@ -60,8 +60,8 @@ public Slice querySliceEventsByKeyword(String keyword, Pageable pageable) .limit(pageable.getPageSize() + 1) .fetch(); - final long remainingSize = Math.max(pageable.getPageSize() - openEvents.size(), 0); - if (remainingSize > 0) { + final long remainingSize = pageable.getPageSize() - openEvents.size(); + if (remainingSize >= 0) { openEvents.addAll(queryClosedEventsByKeywordAndSize(keyword, pageable, remainingSize)); } return SliceUtil.valueOf(openEvents, pageable);