From ce204295d054982141bfa677d2bd2e4ac2c4b009 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Mon, 15 Jan 2024 20:56:25 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[fix]=20#49=20paging=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gachon/checkmate/global/utils/PagingUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java index 4b34d06..34458b5 100644 --- a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java +++ b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java @@ -10,11 +10,11 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class PagingUtils { - public static List convertPaging(List dataList, long page, int size) { - if (dataList.size() <= page * size) + public static List convertPaging(List dataList, long offset, int size) { + if (dataList.size() <= offset) throw new InvalidValueException(INVALID_PAGING_SIZE); - int startIndex = (int) page * size; - int endIndex = Math.min(dataList.size(), (int) (page + 1) * size); + int startIndex = (int) offset; + int endIndex = Math.min(dataList.size(), startIndex + size); return dataList.subList(startIndex, endIndex); } } From 5fd8ac49ab06d2b98c71b475a6e689fba7435e68 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Mon, 15 Jan 2024 21:02:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[fix]=20#49=20=EC=98=A4=EB=A6=84=EC=B0=A8?= =?UTF-8?q?=EC=88=9C=20=EC=A0=95=EB=A0=AC=20=EA=B8=B0=EC=A4=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/repository/PostCustomRepositoryImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index a219a0a..dc99cd9 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -41,6 +41,7 @@ public Optional findPostDetail(Long postId) { .where( eqPostId(postId) ) + .orderBy(post.id.desc()) .fetchOne()); } @@ -67,6 +68,7 @@ public Page searchPosts(PostSearchCondition condition) { eqGenderType(condition.genderType()), validateUserState() ) + .orderBy(post.id.desc()) .fetch(); JPAQuery countQuery = queryFactory @@ -106,6 +108,7 @@ public Page searchPostsWithPaging(PostPagingSearchCondition condi ) .offset(condition.pageable().getOffset()) .limit(condition.pageable().getPageSize()) + .orderBy(post.id.desc()) .fetch(); JPAQuery countQuery = queryFactory From aad792d6ef98c1bb876ed2a65e3e962b0a2ff63d Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Mon, 15 Jan 2024 21:03:38 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[fix]=20#49=20=EC=98=A4=EB=A6=84=EC=B0=A8?= =?UTF-8?q?=EC=88=9C=20=EC=A0=95=EB=A0=AC=20=EA=B8=B0=EC=A4=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/utils/PostSortingUtils.java | 25 ++++++++++++++++--- .../repository/ScrapCustomRepositoryImpl.java | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortingUtils.java b/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortingUtils.java index 8033b7f..133777a 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortingUtils.java +++ b/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortingUtils.java @@ -8,16 +8,33 @@ public class PostSortingUtils { public static void sortByTypeForSearchResults(List posts, PostSortType postSortType) { if (PostSortType.ACCURACY.equals(postSortType)) - sortByAccuracyType(posts); + sortByAccuracy(posts); else if (PostSortType.REMAIN_DATE.equals(postSortType)) sortByRemainDate(posts); + else if (PostSortType.SCRAP.equals(postSortType)) + sortByScrapCount(posts); + } - private static void sortByAccuracyType(List posts) { - posts.sort(Comparator.comparingInt(PostSearchElementResponseDto::accuracy)); + private static void sortByAccuracy(List posts) { + posts.sort(Comparator.comparingInt(PostSearchElementResponseDto::accuracy).reversed() + .thenComparing(dto -> filterRegisterDate(dto.remainDate()))); } private static void sortByRemainDate(List posts) { - posts.sort(Comparator.comparingInt(PostSearchElementResponseDto::remainDate)); + posts.sort(Comparator.comparingInt(dto -> filterPositiveRemainDate(dto.remainDate()))); + } + + private static void sortByScrapCount(List posts) { + posts.sort(Comparator.comparingInt(PostSearchElementResponseDto::scrapCount).reversed() + .thenComparing(dto -> filterRegisterDate(dto.remainDate()))); + } + + private static int filterPositiveRemainDate(int remainDate) { + return remainDate < 0 ? Integer.MAX_VALUE : remainDate; + } + + private static int filterRegisterDate(int remainDate) { + return remainDate < 0 ? Integer.MAX_VALUE : 0; } } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java index 47799b8..31a1904 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java @@ -46,6 +46,7 @@ public Page searchMyScrapPosts(ScrapSearchCondition condition) { eqUserId(condition.userId()), validateUserState() ) + .orderBy(post.id.desc()) .offset(condition.pageable().getOffset()) .limit(condition.pageable().getPageSize()) .fetch(); From 632a43c777b5f1235ade0cb2a835adde8b7d6c34 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Mon, 15 Jan 2024 21:15:49 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20#49=20=EC=A0=95=EB=A0=AC=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gachon/checkmate/domain/post/utils/PostSortType.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortType.java b/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortType.java index ec176f8..5e096c2 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortType.java +++ b/src/main/java/org/gachon/checkmate/domain/post/utils/PostSortType.java @@ -8,9 +8,10 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) @Getter public enum PostSortType implements EnumField { - DATE("1", "register"), - REMAIN_DATE("2", "remain date"), - ACCURACY("3", "accuracy"); + ACCURACY("1", "accuracy"), + REGISTER("2", "register"), + REMAIN_DATE("3", "remain date"), + SCRAP("4", "scrap"); private String code; private String desc;