From 009d8a619f004e547dc8744dfea6a2af39c44d11 Mon Sep 17 00:00:00 2001 From: msk226 Date: Sat, 5 Apr 2025 14:21:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=20[SPOT-253][MODIFY]=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20=EC=B5=9C?= =?UTF-8?q?=EC=8B=A0=20=EA=B2=8C=EC=8B=9C=EA=B8=80=EC=9D=B4=20=EB=A8=BC?= =?UTF-8?q?=EC=A0=80&=20=EC=98=A4=EB=9E=98=EB=90=9C=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=EC=9D=B4=20=EB=92=A4=EB=A1=9C=20=EC=98=A4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/spot/repository/PostRepository.java | 4 ++++ .../com/example/spot/service/post/PostQueryServiceImpl.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/spot/repository/PostRepository.java b/src/main/java/com/example/spot/repository/PostRepository.java index 35fda09f..44a7e384 100644 --- a/src/main/java/com/example/spot/repository/PostRepository.java +++ b/src/main/java/com/example/spot/repository/PostRepository.java @@ -8,8 +8,12 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface PostRepository extends JpaRepository, PostRepositoryCustom { + // 정렬 + Page findByBoardAndPostReportListIsEmptyOrderByCreatedAtDesc(Board board, Pageable pageable); Page findByBoardAndPostReportListIsEmpty(Board board, Pageable pageable); + // 정렬 조건 필요 + Page findByPostReportListIsEmptyOrderByCreatedAtDesc(Pageable pageable); Page findByPostReportListIsEmpty(Pageable pageable); // 모든 게시글 조회 } diff --git a/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java b/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java index 22da9fa8..be6bd8ed 100644 --- a/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java +++ b/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java @@ -101,10 +101,10 @@ public PostPagingResponse getPagingPosts(String type, Pageable pageable) { Page postPage; if (boardType == Board.ALL) { // ALL 타입일 경우 모든 게시글 조회 - postPage = postRepository.findByPostReportListIsEmpty(pageable); + postPage = postRepository.findByPostReportListIsEmptyOrderByCreatedAtDesc(pageable); } else { // 특정 게시판 타입의 게시글 조회 - postPage = postRepository.findByBoardAndPostReportListIsEmpty(boardType, pageable); + postPage = postRepository.findByBoardAndPostReportListIsEmptyOrderByCreatedAtDesc(boardType, pageable); } // PostPagingDetailResponse를 묶어서 응답 리스트 생성 (좋아요 수, 좋아요여부, 스크랩 수, 스크랩여부 포함) From 523c910977f948a2bbe81d5e57fc66e4582c28b0 Mon Sep 17 00:00:00 2001 From: msk226 Date: Sat, 5 Apr 2025 14:22:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=20[SPOT-253][MODIFY]=20=ED=95=B4=EB=8B=B9?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/spot/service/post/PostQueryServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/example/spot/service/post/PostQueryServiceTest.java b/src/test/java/com/example/spot/service/post/PostQueryServiceTest.java index 67e71bed..222e8ea9 100644 --- a/src/test/java/com/example/spot/service/post/PostQueryServiceTest.java +++ b/src/test/java/com/example/spot/service/post/PostQueryServiceTest.java @@ -266,7 +266,7 @@ void getPagingPosts_All_Success() { List posts = List.of(post1, post2); postPage = new PageImpl<>(posts, pageable, 2); - when(postRepository.findByPostReportListIsEmpty(pageable)).thenReturn(postPage); + when(postRepository.findByPostReportListIsEmptyOrderByCreatedAtDesc(pageable)).thenReturn(postPage); // when PostPagingResponse result = postQueryService.getPagingPosts("ALL", pageable); @@ -292,7 +292,7 @@ void getPagingPosts_Type_Success() { List posts = List.of(post2); postPage = new PageImpl<>(posts, pageable, 1); - when(postRepository.findByBoardAndPostReportListIsEmpty(Board.INFORMATION_SHARING, pageable)).thenReturn(postPage); + when(postRepository.findByBoardAndPostReportListIsEmptyOrderByCreatedAtDesc(Board.INFORMATION_SHARING, pageable)).thenReturn(postPage); // when PostPagingResponse result = postQueryService.getPagingPosts("INFORMATION_SHARING", pageable);