From 0633ef1fed36eb71c9544557420d4e416434ccf3 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 13:05:10 +0900 Subject: [PATCH 01/21] =?UTF-8?q?fix:=20=EB=B3=B4=EB=93=9C=EC=99=80=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=8F=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=95=EB=A0=AC=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/board/controller/BoardController.java | 2 +- .../community/post/repository/PostRepository.java | 3 ++- .../community/post/service/PostQueryService.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java b/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java index 89970d334..552ad1717 100644 --- a/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java +++ b/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java @@ -37,7 +37,7 @@ public ResponseEntity findPostsByCodeAndCategory( @PathVariable(value = "code") String code, @RequestParam(value = "category", defaultValue = "전체") String category) { List postsByCodeAndPostCategory = postQueryService - .findPostsByCodeAndPostCategory(code, category, siteUserId); + .findPostsByCodeAndPostCategoryOrderByCreatedAt(code, category, siteUserId); return ResponseEntity.ok().body(postsByCodeAndPostCategory); } } diff --git a/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java b/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java index aad12fab1..ab878a73a 100644 --- a/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java +++ b/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java @@ -14,7 +14,7 @@ public interface PostRepository extends JpaRepository { - List findByBoardCode(String boardCode); + List findByBoardCodeOrderByCreatedAtDesc(String boardCode); @Query(""" SELECT p FROM Post p @@ -22,6 +22,7 @@ public interface PostRepository extends JpaRepository { AND p.siteUserId NOT IN ( SELECT ub.blockedId FROM UserBlock ub WHERE ub.blockerId = :siteUserId ) + ORDER BY p.createdAt DESC """) List findByBoardCodeExcludingBlockedUsers(@Param("boardCode") String boardCode, @Param("siteUserId") Long siteUserId); diff --git a/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java b/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java index 9602cd454..66e55b553 100644 --- a/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java +++ b/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java @@ -46,7 +46,7 @@ public class PostQueryService { private final RedisUtils redisUtils; @Transactional(readOnly = true) - public List findPostsByCodeAndPostCategory(String code, String category, Long siteUserId) { + public List findPostsByCodeAndPostCategoryOrderByCreatedAt(String code, String category, Long siteUserId) { String boardCode = validateCode(code); PostCategory postCategory = validatePostCategory(category); @@ -56,7 +56,7 @@ public List findPostsByCodeAndPostCategory(String code, String if (siteUserId != null) { postList = postRepository.findByBoardCodeExcludingBlockedUsers(boardCode, siteUserId); } else { - postList = postRepository.findByBoardCode(boardCode); + postList = postRepository.findByBoardCodeOrderByCreatedAtDesc(boardCode); } return PostListResponse.from(getPostListByPostCategory(postList, postCategory)); } From 89b0d95ba2392893b6ce85c8bb5e2ca75a8bcca0 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 13:05:43 +0900 Subject: [PATCH 02/21] =?UTF-8?q?test:=20=EB=B3=B4=EB=93=9C=EC=99=80=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=8F=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=95=EB=A0=AC=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0=20-=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=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 --- .../post/service/PostQueryServiceTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index beeb3fc88..9fb12467d 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -97,7 +97,7 @@ void setUp() { @Test void 게시판_코드와_카테고리로_게시글_목록을_조회한다() { // given - List posts = List.of(post1, post2, post3); + List posts = List.of(post3, post2, post1); List expectedPosts = posts.stream() .filter(post -> post.getCategory().equals(PostCategory.자유) && post.getBoardCode().equals(BoardCode.FREE.name())) @@ -105,7 +105,7 @@ void setUp() { List expectedResponses = PostListResponse.from(expectedPosts); // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategory( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( BoardCode.FREE.name(), PostCategory.자유.name(), null @@ -121,14 +121,14 @@ void setUp() { @Test void 전체_카테고리로_조회시_해당_게시판의_모든_게시글을_조회한다() { // given - List posts = List.of(post1, post2, post3); + List posts = List.of(post3, post2, post1); List expectedPosts = posts.stream() .filter(post -> post.getBoardCode().equals(BoardCode.FREE.name())) .toList(); List expectedResponses = PostListResponse.from(expectedPosts); // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategory( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( BoardCode.FREE.name(), PostCategory.전체.name(), null @@ -200,7 +200,7 @@ void setUp() { postImageFixture.게시글_이미지(secondImageUrl, post1); // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategory( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( BoardCode.FREE.name(), PostCategory.전체.name(), null @@ -218,7 +218,7 @@ void setUp() { @Test void 게시글에_이미지가_없다면_썸네일로_null을_반환한다() { // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategory( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( BoardCode.FREE.name(), PostCategory.전체.name(), null @@ -244,7 +244,7 @@ void setUp() { Post notBlockedPost = postFixture.게시글(board, notBlockedUser); // when - List response = postQueryService.findPostsByCodeAndPostCategory( + List response = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( BoardCode.FREE.name(), PostCategory.전체.name(), user.getId() From 6e164c6b9fe4ec3fc49a579097f3f15eba94fa0d Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 15:20:39 +0900 Subject: [PATCH 03/21] =?UTF-8?q?fix:=20=EC=BD=94=EB=A9=98=ED=8A=B8=20?= =?UTF-8?q?=ED=8A=B8=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EB=A0=AC=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/comment/repository/CommentRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java b/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java index 39b42f49a..7d5f2e8b0 100644 --- a/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java +++ b/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java @@ -34,7 +34,7 @@ WHERE c.site_user_id NOT IN ( ) ) SELECT * FROM CommentTree - ORDER BY path + ORDER BY path, created_at """, nativeQuery = true) List findCommentTreeByPostIdExcludingBlockedUsers(@Param("postId") Long postId, @Param("siteUserId") Long siteUserId); From a61e8aedb9cc21b65a47e85ba5b3ce035c436727 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 15:21:20 +0900 Subject: [PATCH 04/21] =?UTF-8?q?test:=20=EC=BD=94=EB=A9=98=ED=8A=B8=20?= =?UTF-8?q?=ED=8A=B8=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EB=A0=AC=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20-=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 --- .../comment/service/CommentServiceTest.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index 63a824e53..6d75f180b 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -82,15 +82,19 @@ void setUp() { class 댓글_조회_테스트 { @Test - void 게시글의_모든_댓글을_조회한다() { + void 게시글의_모든_댓글과_대댓글을_생성시간_기준으로_정렬해_조회한다() { // given Comment parentComment = commentFixture.부모_댓글("부모 댓글", post, user1); - Comment childComment = commentFixture.자식_댓글("자식 댓글 1", post, user2, parentComment); - List comments = List.of(parentComment, childComment); + Comment childComment1 = commentFixture.자식_댓글("자식 댓글 1", post, user2, parentComment); + Comment childComment2 = commentFixture.자식_댓글("자식 댓글 2", post, user1, parentComment); + Comment childComment3 = commentFixture.자식_댓글("자식 댓글 3", post, user2, parentComment); + List comments = List.of(parentComment, childComment1, childComment2, childComment3); // when List responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); + System.out.println(responses); + // then assertAll( () -> assertThat(responses).hasSize(comments.size()), @@ -103,10 +107,26 @@ class 댓글_조회_테스트 { () -> assertThat(response.isOwner()).isTrue() )), () -> assertThat(responses) - .filteredOn(response -> response.id().equals(childComment.getId())) + .filteredOn(response -> response.id().equals(childComment1.getId())) + .singleElement() + .satisfies(response -> assertAll( + () -> assertThat(response.id()).isEqualTo(childComment1.getId()), + () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), + () -> assertThat(response.isOwner()).isFalse() + )), + () -> assertThat(responses) + .filteredOn(response -> response.id().equals(childComment2.getId())) + .singleElement() + .satisfies(response -> assertAll( + () -> assertThat(response.id()).isEqualTo(childComment2.getId()), + () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), + () -> assertThat(response.isOwner()).isTrue() + )), + () -> assertThat(responses) + .filteredOn(response -> response.id().equals(childComment3.getId())) .singleElement() .satisfies(response -> assertAll( - () -> assertThat(response.id()).isEqualTo(childComment.getId()), + () -> assertThat(response.id()).isEqualTo(childComment3.getId()), () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), () -> assertThat(response.isOwner()).isFalse() )) From 8394ca031ab1b9c326d72d30a2f67e9168450a1f Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 15:43:31 +0900 Subject: [PATCH 05/21] =?UTF-8?q?style:=20PostRepository=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD=20findByBoardC?= =?UTF-8?q?odeExcludingBlockedUsers=20->=20findByBoardCodeExcludingBlocked?= =?UTF-8?q?UsersOrderByCreatedAtDesc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/board/controller/BoardController.java | 2 +- .../community/post/repository/PostRepository.java | 2 +- .../community/post/service/PostQueryService.java | 4 ++-- .../community/post/service/PostQueryServiceTest.java | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java b/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java index 552ad1717..e8dd61473 100644 --- a/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java +++ b/src/main/java/com/example/solidconnection/community/board/controller/BoardController.java @@ -37,7 +37,7 @@ public ResponseEntity findPostsByCodeAndCategory( @PathVariable(value = "code") String code, @RequestParam(value = "category", defaultValue = "전체") String category) { List postsByCodeAndPostCategory = postQueryService - .findPostsByCodeAndPostCategoryOrderByCreatedAt(code, category, siteUserId); + .findPostsByCodeAndPostCategoryOrderByCreatedAtDesc(code, category, siteUserId); return ResponseEntity.ok().body(postsByCodeAndPostCategory); } } diff --git a/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java b/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java index ab878a73a..aea6e54a4 100644 --- a/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java +++ b/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java @@ -24,7 +24,7 @@ AND p.siteUserId NOT IN ( ) ORDER BY p.createdAt DESC """) - List findByBoardCodeExcludingBlockedUsers(@Param("boardCode") String boardCode, @Param("siteUserId") Long siteUserId); + List findByBoardCodeExcludingBlockedUsersOrderByCreatedAtDesc(@Param("boardCode") String boardCode, @Param("siteUserId") Long siteUserId); @EntityGraph(attributePaths = {"postImageList"}) Optional findPostById(Long id); diff --git a/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java b/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java index 66e55b553..97ecad30f 100644 --- a/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java +++ b/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java @@ -46,7 +46,7 @@ public class PostQueryService { private final RedisUtils redisUtils; @Transactional(readOnly = true) - public List findPostsByCodeAndPostCategoryOrderByCreatedAt(String code, String category, Long siteUserId) { + public List findPostsByCodeAndPostCategoryOrderByCreatedAtDesc(String code, String category, Long siteUserId) { String boardCode = validateCode(code); PostCategory postCategory = validatePostCategory(category); @@ -54,7 +54,7 @@ public List findPostsByCodeAndPostCategoryOrderByCreatedAt(Str List postList; // todo : 추후 개선 필요(현재 최신순으로 응답나가지 않고 있음) if (siteUserId != null) { - postList = postRepository.findByBoardCodeExcludingBlockedUsers(boardCode, siteUserId); + postList = postRepository.findByBoardCodeExcludingBlockedUsersOrderByCreatedAtDesc(boardCode, siteUserId); } else { postList = postRepository.findByBoardCodeOrderByCreatedAtDesc(boardCode); } diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index 9fb12467d..2838613fc 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -105,7 +105,7 @@ void setUp() { List expectedResponses = PostListResponse.from(expectedPosts); // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc( BoardCode.FREE.name(), PostCategory.자유.name(), null @@ -128,7 +128,7 @@ void setUp() { List expectedResponses = PostListResponse.from(expectedPosts); // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc( BoardCode.FREE.name(), PostCategory.전체.name(), null @@ -200,7 +200,7 @@ void setUp() { postImageFixture.게시글_이미지(secondImageUrl, post1); // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc( BoardCode.FREE.name(), PostCategory.전체.name(), null @@ -218,7 +218,7 @@ void setUp() { @Test void 게시글에_이미지가_없다면_썸네일로_null을_반환한다() { // when - List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc( BoardCode.FREE.name(), PostCategory.전체.name(), null @@ -244,7 +244,7 @@ void setUp() { Post notBlockedPost = postFixture.게시글(board, notBlockedUser); // when - List response = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAt( + List response = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc( BoardCode.FREE.name(), PostCategory.전체.name(), user.getId() From 7120341f6ad4fadd420071089e4cc3e2ce502228 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 16:51:54 +0900 Subject: [PATCH 06/21] =?UTF-8?q?chore:=20todo=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/post/service/PostQueryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java b/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java index 97ecad30f..413ec400d 100644 --- a/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java +++ b/src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java @@ -52,7 +52,7 @@ public List findPostsByCodeAndPostCategoryOrderByCreatedAtDesc PostCategory postCategory = validatePostCategory(category); boardRepository.getByCode(boardCode); - List postList; // todo : 추후 개선 필요(현재 최신순으로 응답나가지 않고 있음) + List postList; if (siteUserId != null) { postList = postRepository.findByBoardCodeExcludingBlockedUsersOrderByCreatedAtDesc(boardCode, siteUserId); } else { From c1344f606f90bde18cd0eb3cfb0b3dbfda2f420b Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 16:52:57 +0900 Subject: [PATCH 07/21] =?UTF-8?q?chore:=20=EB=94=94=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/comment/service/CommentServiceTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index 6d75f180b..1df858a36 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -93,8 +93,6 @@ class 댓글_조회_테스트 { // when List responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); - System.out.println(responses); - // then assertAll( () -> assertThat(responses).hasSize(comments.size()), From ec76fad725afad33376cf1d7cb1db87ff3e978e6 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Tue, 30 Sep 2025 17:07:13 +0900 Subject: [PATCH 08/21] =?UTF-8?q?test:=20=EB=82=B4=EB=A6=BC=EC=B0=A8?= =?UTF-8?q?=EC=88=9C=20=EC=A0=95=EB=A0=AC=20=EA=B2=80=EC=A6=9D=EC=9D=B4=20?= =?UTF-8?q?=EB=B9=84=EA=B2=B0=EC=A0=95=EC=A0=81=EC=9D=BC=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/common/BaseEntity.java | 6 ++++++ .../community/post/fixture/PostFixture.java | 21 +++++++++++++++++++ .../post/fixture/PostFixtureBuilder.java | 16 ++++++++++++++ .../post/service/PostQueryServiceTest.java | 10 +++++---- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/solidconnection/common/BaseEntity.java b/src/main/java/com/example/solidconnection/common/BaseEntity.java index b3b597350..42a6139aa 100644 --- a/src/main/java/com/example/solidconnection/common/BaseEntity.java +++ b/src/main/java/com/example/solidconnection/common/BaseEntity.java @@ -8,6 +8,8 @@ import jakarta.persistence.PrePersist; import jakarta.persistence.PreUpdate; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; + import lombok.Getter; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -33,4 +35,8 @@ public void onPrePersist() { public void onPreUpdate() { this.updatedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); } + + public void setCreatedAt(ZonedDateTime createdAt) { + this.createdAt = createdAt.truncatedTo(ChronoUnit.MICROS); + } } diff --git a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java index 5ddf13888..d215e213f 100644 --- a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java +++ b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java @@ -47,4 +47,25 @@ public class PostFixture { .siteUser(siteUser) .create(); } + + public Post 게시글_특정_시간_이후로_저장( + String title, + String content, + Boolean isQuestion, + PostCategory postCategory, + Board board, + SiteUser siteUser, + int time + ) { + return postFixtureBuilder + .title(title) + .content(content) + .isQuestion(isQuestion) + .likeCount(0L) + .viewCount(0L) + .postCategory(postCategory) + .board(board) + .siteUser(siteUser) + .createAfterCertainTime(time); + } } diff --git a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java index 3473d61e2..372785ae6 100644 --- a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java +++ b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java @@ -8,6 +8,9 @@ import lombok.RequiredArgsConstructor; import org.springframework.boot.test.context.TestComponent; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; + @TestComponent @RequiredArgsConstructor public class PostFixtureBuilder { @@ -74,4 +77,17 @@ public Post create() { post.setBoardAndSiteUserId(board.getCode(), siteUser.getId()); return postRepository.save(post); } + + public Post createAfterCertainTime(int time) { + Post post = new Post( + title, + content, + isQuestion, + likeCount, + viewCount, + postCategory); + post.setBoardAndSiteUserId(board.getCode(), siteUser.getId()); + post.setCreatedAt(ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(time)); + return postRepository.save(post); + } } diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index 2838613fc..971873aaf 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -76,21 +76,23 @@ void setUp() { boardFixture.자유게시판(), user ); - post2 = postFixture.게시글( + post2 = postFixture.게시글_특정_시간_이후로_저장( "제목2", "내용2", false, PostCategory.자유, boardFixture.미주권(), - user + user, + 3 ); - post3 = postFixture.게시글( + post3 = postFixture.게시글_특정_시간_이후로_저장( "제목3", "내용3", true, PostCategory.질문, boardFixture.자유게시판(), - user + user, + 6 ); } From 563c71dc73fecbb9d6c7f1afcc2cd78130eae335 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 13:55:35 +0900 Subject: [PATCH 09/21] Revert "chore : debug code delete" This reverts commit 5540b44241224afbc090344501380424c4dd3d19. --- .../community/comment/service/CommentServiceTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index 1df858a36..6d75f180b 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -93,6 +93,8 @@ class 댓글_조회_테스트 { // when List responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); + System.out.println(responses); + // then assertAll( () -> assertThat(responses).hasSize(comments.size()), From 920002ec6c60f331642ef8cd21a1135ccba34263 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 16:13:08 +0900 Subject: [PATCH 10/21] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=EA=B0=80=20=ED=94=84=EB=A1=9C=EB=8D=95?= =?UTF-8?q?=EC=85=98=20=EC=BD=94=EB=93=9C=EC=97=90=EA=B2=8C=20=EC=98=81?= =?UTF-8?q?=ED=96=A5=20=EB=AF=B8=EC=B9=98=EC=A7=80=20=EC=95=8A=EA=B2=8C=20?= =?UTF-8?q?reflaction=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20createdAt?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/common/BaseEntity.java | 4 ---- .../common/helper/TestTimeHelper.java | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java diff --git a/src/main/java/com/example/solidconnection/common/BaseEntity.java b/src/main/java/com/example/solidconnection/common/BaseEntity.java index 42a6139aa..816c94094 100644 --- a/src/main/java/com/example/solidconnection/common/BaseEntity.java +++ b/src/main/java/com/example/solidconnection/common/BaseEntity.java @@ -35,8 +35,4 @@ public void onPrePersist() { public void onPreUpdate() { this.updatedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); } - - public void setCreatedAt(ZonedDateTime createdAt) { - this.createdAt = createdAt.truncatedTo(ChronoUnit.MICROS); - } } diff --git a/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java b/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java new file mode 100644 index 000000000..def1dfcb4 --- /dev/null +++ b/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java @@ -0,0 +1,19 @@ +package com.example.solidconnection.common.helper; + +import com.example.solidconnection.common.BaseEntity; + +import java.lang.reflect.Field; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; + +public class TestTimeHelper { + public static void setCreatedAt(BaseEntity entity, ZonedDateTime time) { + try { + Field field = BaseEntity.class.getDeclaredField("createdAt"); + field.setAccessible(true); + field.set(entity, time.truncatedTo(ChronoUnit.MICROS)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} From d6ba7be1938b1403ad62444944e21e5506c2546e Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 16:14:08 +0900 Subject: [PATCH 11/21] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=EA=B0=80=20=ED=94=84=EB=A1=9C=EB=8D=95?= =?UTF-8?q?=EC=85=98=20=EC=BD=94=EB=93=9C=EC=97=90=EA=B2=8C=20=EC=98=81?= =?UTF-8?q?=ED=96=A5=20=EB=AF=B8=EC=B9=98=EC=A7=80=20=EC=95=8A=EA=B2=8C=20?= =?UTF-8?q?TestTimeHelper=20=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20Fix?= =?UTF-8?q?ture=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/comment/fixture/CommentFixture.java | 15 +++++++++++++++ .../comment/fixture/CommentFixtureBuilder.java | 13 +++++++++++++ .../community/post/fixture/PostFixture.java | 6 +++--- .../post/fixture/PostFixtureBuilder.java | 13 ++++++++----- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java b/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java index 4d0f3b438..4bc1579d7 100644 --- a/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java +++ b/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java @@ -32,4 +32,19 @@ public class CommentFixture { .parentComment(parentComment) .createChild(); } + + public Comment 자식_댓글_지연저장( + String content, + Post post, + SiteUser siteUser, + Comment parentComment, + long secondsDelay + ) { + return commentFixtureBuilder + .content(content) + .post(post) + .siteUser(siteUser) + .parentComment(parentComment) + .createChildWithDelaySeconds(secondsDelay); + } } diff --git a/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java b/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java index 02a8ba889..f4ec2f318 100644 --- a/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java +++ b/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java @@ -1,5 +1,6 @@ package com.example.solidconnection.community.comment.fixture; +import com.example.solidconnection.common.helper.TestTimeHelper; import com.example.solidconnection.community.comment.domain.Comment; import com.example.solidconnection.community.comment.repository.CommentRepository; import com.example.solidconnection.community.post.domain.Post; @@ -50,4 +51,16 @@ public Comment createChild() { comment.setParentCommentAndPostAndSiteUserId(parentComment, post, siteUser.getId()); return commentRepository.save(comment); } + + public Comment createChildWithDelaySeconds(long seconds) { + Comment comment = new Comment(content); + comment.setPostAndSiteUserId(post, siteUser.getId()); + comment.setParentCommentAndPostAndSiteUserId(parentComment, post, siteUser.getId()); + + Comment saved = commentRepository.save(comment); + + TestTimeHelper.setCreatedAt(saved, saved.getCreatedAt().plusSeconds(seconds)); + + return commentRepository.save(saved); + } } diff --git a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java index d215e213f..51d2dcb2d 100644 --- a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java +++ b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java @@ -48,14 +48,14 @@ public class PostFixture { .create(); } - public Post 게시글_특정_시간_이후로_저장( + public Post 게시글_지연저장( String title, String content, Boolean isQuestion, PostCategory postCategory, Board board, SiteUser siteUser, - int time + long secondsDelay ) { return postFixtureBuilder .title(title) @@ -66,6 +66,6 @@ public class PostFixture { .postCategory(postCategory) .board(board) .siteUser(siteUser) - .createAfterCertainTime(time); + .createWithDelaySeconds(secondsDelay); } } diff --git a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java index 372785ae6..279fbb3cc 100644 --- a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java +++ b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java @@ -1,5 +1,6 @@ package com.example.solidconnection.community.post.fixture; +import com.example.solidconnection.common.helper.TestTimeHelper; import com.example.solidconnection.community.board.domain.Board; import com.example.solidconnection.community.post.domain.Post; import com.example.solidconnection.community.post.domain.PostCategory; @@ -8,9 +9,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.boot.test.context.TestComponent; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; - @TestComponent @RequiredArgsConstructor public class PostFixtureBuilder { @@ -78,7 +76,7 @@ public Post create() { return postRepository.save(post); } - public Post createAfterCertainTime(int time) { + public Post createWithDelaySeconds(long seconds) { Post post = new Post( title, content, @@ -87,7 +85,12 @@ public Post createAfterCertainTime(int time) { viewCount, postCategory); post.setBoardAndSiteUserId(board.getCode(), siteUser.getId()); - post.setCreatedAt(ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(time)); + + Post saved = postRepository.save(post); + + System.out.println(saved); + + TestTimeHelper.setCreatedAt(saved, saved.getCreatedAt().plusSeconds(seconds)); return postRepository.save(post); } } From a60743106b31a317597bcb904cfe028bcfcb59b2 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 16:15:42 +0900 Subject: [PATCH 12/21] =?UTF-8?q?test:=20Comment=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EC=A0=95=EB=A0=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 변경된 메서드: - 게시글의_모든_댓글과_대댓글을_생성시간_기준으로_정렬해_조회한다 --- .../comment/service/CommentServiceTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index 6d75f180b..a25f30810 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -86,8 +86,8 @@ class 댓글_조회_테스트 { // given Comment parentComment = commentFixture.부모_댓글("부모 댓글", post, user1); Comment childComment1 = commentFixture.자식_댓글("자식 댓글 1", post, user2, parentComment); - Comment childComment2 = commentFixture.자식_댓글("자식 댓글 2", post, user1, parentComment); - Comment childComment3 = commentFixture.자식_댓글("자식 댓글 3", post, user2, parentComment); + Comment childComment2 = commentFixture.자식_댓글_지연저장("자식 댓글 2", post, user1, parentComment, 3); + Comment childComment3 = commentFixture.자식_댓글_지연저장("자식 댓글 3", post, user2, parentComment, 5); List comments = List.of(parentComment, childComment1, childComment2, childComment3); // when @@ -129,7 +129,15 @@ class 댓글_조회_테스트 { () -> assertThat(response.id()).isEqualTo(childComment3.getId()), () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), () -> assertThat(response.isOwner()).isFalse() - )) + )), + () -> assertThat(responses) + .extracting("id") + .containsExactly( + parentComment.getId(), + childComment1.getId(), + childComment2.getId(), + childComment3.getId() + ) ); } From f45446a0dd86ff380feea1d4bb4a984df259129b Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 16:17:31 +0900 Subject: [PATCH 13/21] =?UTF-8?q?test:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=88=9C=EC=84=9C=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=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 변경된 메서드: - 게시판_코드와_카테고리로_게시글_목록을_최신순으로_조회한다 --- .../post/service/PostQueryServiceTest.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index 971873aaf..1e57908ff 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -64,6 +64,7 @@ class PostQueryServiceTest { private Post post1; private Post post2; private Post post3; + private Post post4; @BeforeEach void setUp() { @@ -76,7 +77,7 @@ void setUp() { boardFixture.자유게시판(), user ); - post2 = postFixture.게시글_특정_시간_이후로_저장( + post2 = postFixture.게시글_지연저장( "제목2", "내용2", false, @@ -85,7 +86,7 @@ void setUp() { user, 3 ); - post3 = postFixture.게시글_특정_시간_이후로_저장( + post3 = postFixture.게시글_지연저장( "제목3", "내용3", true, @@ -94,12 +95,21 @@ void setUp() { user, 6 ); + post4 = postFixture.게시글_지연저장( + "제목1", + "내용1", + false, + PostCategory.자유, + boardFixture.자유게시판(), + user, + 9 + ); } @Test - void 게시판_코드와_카테고리로_게시글_목록을_조회한다() { + void 게시판_코드와_카테고리로_게시글_목록을_최신순으로_조회한다() { // given - List posts = List.of(post3, post2, post1); + List posts = List.of(post4, post3, post2, post1); List expectedPosts = posts.stream() .filter(post -> post.getCategory().equals(PostCategory.자유) && post.getBoardCode().equals(BoardCode.FREE.name())) @@ -114,10 +124,15 @@ void setUp() { ); // then - assertThat(actualResponses) - .usingRecursiveComparison() - .ignoringFieldsOfTypes(ZonedDateTime.class) - .isEqualTo(expectedResponses); + assertAll( + () -> assertThat(actualResponses) + .usingRecursiveComparison() + .ignoringFieldsOfTypes(ZonedDateTime.class) + .isEqualTo(expectedResponses), + () -> assertThat(actualResponses) + .extracting(PostListResponse::id) + .containsExactly(post4.getId(), post1.getId()) + ); } @Test From 6edde9b30f78f06ad63e636cca61677163c90c47 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 16:34:13 +0900 Subject: [PATCH 14/21] =?UTF-8?q?test:=20=EC=B0=A8=EB=8B=A8=ED=95=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=9C=EC=99=B8=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=EB=93=A4=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 변경된 메서드: - 차단한_사용자의_댓글은_제외된다 --- .../comment/service/CommentServiceTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index a25f30810..ea31b38af 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -226,10 +226,11 @@ class 댓글_조회_테스트 { userBlockFixture.유저_차단(user1.getId(), user2.getId()); Comment parentComment1 = commentFixture.부모_댓글("부모 댓글1", post, user1); Comment childComment1 = commentFixture.자식_댓글("자식 댓글1", post, user1, parentComment1); - Comment childComment2 = commentFixture.자식_댓글("자식 댓글2", post, user2, parentComment1); - Comment parentCommen2 = commentFixture.부모_댓글("부모 댓글2", post, user2); - Comment childComment3 = commentFixture.자식_댓글("자식 댓글1", post, user1, parentCommen2); - Comment childComment4 = commentFixture.자식_댓글("자식 댓글1", post, user1, parentCommen2); + Comment childComment2 = commentFixture.자식_댓글_지연저장("자식 댓글2", post, user2, parentComment1, 2); + Comment childComment3 = commentFixture.자식_댓글_지연저장("자식 댓글3", post, user1, parentComment1, 3); + Comment parentComment2 = commentFixture.부모_댓글("부모 댓글2", post, user2); + Comment childComment4 = commentFixture.자식_댓글("자식 댓글1", post, user1, parentComment2); + Comment childComment5 = commentFixture.자식_댓글_지연저장("자식 댓글1", post, user1, parentComment2, 2); // when @@ -237,13 +238,16 @@ class 댓글_조회_테스트 { // then assertAll( - () -> assertThat(responses).hasSize(2), + () -> assertThat(responses).hasSize(3), () -> assertThat(responses) .extracting(PostFindCommentResponse::id) - .containsExactly(parentComment1.getId(), childComment1.getId()), + .containsExactly(parentComment1.getId(), childComment1.getId(), childComment3.getId()), () -> assertThat(responses) .extracting(PostFindCommentResponse::id) - .doesNotContain(childComment2.getId(), parentCommen2.getId(), childComment3.getId(), childComment4.getId()) + .doesNotContain(childComment2.getId(), parentComment2.getId(), childComment4.getId(), childComment5.getId()), + () -> assertThat(responses) + .extracting(PostFindCommentResponse::id) + .containsSubsequence(parentComment1.getId(), childComment1.getId(), childComment3.getId()) ); } } From 58b8bdf53bf6dbb8687e5716a13637a4c1d9036e Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Wed, 1 Oct 2025 16:47:35 +0900 Subject: [PATCH 15/21] =?UTF-8?q?fix:=20rebase=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=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 변경된 메서드: - 게시판_코드와_카테고리로_게시글_목록을_최신순으로_조회한다 --- .../community/post/service/PostQueryServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index 1e57908ff..054718bc5 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -138,7 +138,7 @@ void setUp() { @Test void 전체_카테고리로_조회시_해당_게시판의_모든_게시글을_조회한다() { // given - List posts = List.of(post3, post2, post1); + List posts = List.of(post4, post3, post2, post1); List expectedPosts = posts.stream() .filter(post -> post.getBoardCode().equals(BoardCode.FREE.name())) .toList(); From 244b292870696e79ac81df98348ea5c17a60a0de Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Thu, 2 Oct 2025 13:45:08 +0900 Subject: [PATCH 16/21] =?UTF-8?q?test:=20import=20=EA=B5=AC=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=20&=20=EB=94=94=EB=B2=84=EA=B9=85=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/common/BaseEntity.java | 11 ++++---- .../comment/service/CommentServiceTest.java | 26 ++++++------------- .../post/fixture/PostFixtureBuilder.java | 2 -- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/example/solidconnection/common/BaseEntity.java b/src/main/java/com/example/solidconnection/common/BaseEntity.java index 816c94094..febf5e77c 100644 --- a/src/main/java/com/example/solidconnection/common/BaseEntity.java +++ b/src/main/java/com/example/solidconnection/common/BaseEntity.java @@ -1,20 +1,19 @@ package com.example.solidconnection.common; -import static java.time.ZoneOffset.UTC; -import static java.time.temporal.ChronoUnit.MICROS; - import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PrePersist; import jakarta.persistence.PreUpdate; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; - import lombok.Getter; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.time.ZonedDateTime; + +import static java.time.ZoneOffset.UTC; +import static java.time.temporal.ChronoUnit.MICROS; + @MappedSuperclass @EntityListeners(AuditingEntityListener.class) @Getter diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index ea31b38af..a181dda24 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -1,22 +1,9 @@ package com.example.solidconnection.community.comment.service; -import static com.example.solidconnection.common.exception.ErrorCode.CAN_NOT_UPDATE_DEPRECATED_COMMENT; -import static com.example.solidconnection.common.exception.ErrorCode.INVALID_COMMENT_ID; -import static com.example.solidconnection.common.exception.ErrorCode.INVALID_COMMENT_LEVEL; -import static com.example.solidconnection.common.exception.ErrorCode.INVALID_POST_ACCESS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertAll; - import com.example.solidconnection.common.exception.CustomException; import com.example.solidconnection.community.board.fixture.BoardFixture; import com.example.solidconnection.community.comment.domain.Comment; -import com.example.solidconnection.community.comment.dto.CommentCreateRequest; -import com.example.solidconnection.community.comment.dto.CommentCreateResponse; -import com.example.solidconnection.community.comment.dto.CommentDeleteResponse; -import com.example.solidconnection.community.comment.dto.CommentUpdateRequest; -import com.example.solidconnection.community.comment.dto.CommentUpdateResponse; -import com.example.solidconnection.community.comment.dto.PostFindCommentResponse; +import com.example.solidconnection.community.comment.dto.*; import com.example.solidconnection.community.comment.fixture.CommentFixture; import com.example.solidconnection.community.comment.repository.CommentRepository; import com.example.solidconnection.community.post.domain.Post; @@ -28,13 +15,19 @@ import com.example.solidconnection.siteuser.fixture.UserBlockFixture; import com.example.solidconnection.support.TestContainerSpringBootTest; import jakarta.transaction.Transactional; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; + +import static com.example.solidconnection.common.exception.ErrorCode.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + @TestContainerSpringBootTest @DisplayName("댓글 서비스 테스트") class CommentServiceTest { @@ -93,11 +86,8 @@ class 댓글_조회_테스트 { // when List responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); - System.out.println(responses); - // then assertAll( - () -> assertThat(responses).hasSize(comments.size()), () -> assertThat(responses) .filteredOn(response -> response.id().equals(parentComment.getId())) .singleElement() diff --git a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java index 279fbb3cc..235ae75b6 100644 --- a/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java +++ b/src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java @@ -88,8 +88,6 @@ public Post createWithDelaySeconds(long seconds) { Post saved = postRepository.save(post); - System.out.println(saved); - TestTimeHelper.setCreatedAt(saved, saved.getCreatedAt().plusSeconds(seconds)); return postRepository.save(post); } From 6b561f7d35ea11b48ff40e71ae26bd3d03094237 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Thu, 2 Oct 2025 13:55:21 +0900 Subject: [PATCH 17/21] =?UTF-8?q?refactor:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=20=EB=A1=9C=EC=A7=81=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 제거된 메서드: - setPostAndSiteUserId --- .../community/comment/fixture/CommentFixtureBuilder.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java b/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java index f4ec2f318..7c380a103 100644 --- a/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java +++ b/src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java @@ -47,14 +47,12 @@ public Comment createParent() { public Comment createChild() { Comment comment = new Comment(content); - comment.setPostAndSiteUserId(post, siteUser.getId()); comment.setParentCommentAndPostAndSiteUserId(parentComment, post, siteUser.getId()); return commentRepository.save(comment); } public Comment createChildWithDelaySeconds(long seconds) { Comment comment = new Comment(content); - comment.setPostAndSiteUserId(post, siteUser.getId()); comment.setParentCommentAndPostAndSiteUserId(parentComment, post, siteUser.getId()); Comment saved = commentRepository.save(comment); From e193241ae35362b9d6d9179588ec7dd1c077e370 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Thu, 2 Oct 2025 13:57:35 +0900 Subject: [PATCH 18/21] =?UTF-8?q?test:=20=EC=A4=91=EB=B3=B5=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 제거된 검증: - filteredOn에 의해 검증된 comment.Id 값을 다시 한 번 검증하는 isEqualTo(comment.getId())로직 --- .../community/comment/service/CommentServiceTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index a181dda24..5a065d412 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -92,7 +92,6 @@ class 댓글_조회_테스트 { .filteredOn(response -> response.id().equals(parentComment.getId())) .singleElement() .satisfies(response -> assertAll( - () -> assertThat(response.id()).isEqualTo(parentComment.getId()), () -> assertThat(response.parentId()).isNull(), () -> assertThat(response.isOwner()).isTrue() )), @@ -100,7 +99,6 @@ class 댓글_조회_테스트 { .filteredOn(response -> response.id().equals(childComment1.getId())) .singleElement() .satisfies(response -> assertAll( - () -> assertThat(response.id()).isEqualTo(childComment1.getId()), () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), () -> assertThat(response.isOwner()).isFalse() )), @@ -108,7 +106,6 @@ class 댓글_조회_테스트 { .filteredOn(response -> response.id().equals(childComment2.getId())) .singleElement() .satisfies(response -> assertAll( - () -> assertThat(response.id()).isEqualTo(childComment2.getId()), () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), () -> assertThat(response.isOwner()).isTrue() )), @@ -116,7 +113,6 @@ class 댓글_조회_테스트 { .filteredOn(response -> response.id().equals(childComment3.getId())) .singleElement() .satisfies(response -> assertAll( - () -> assertThat(response.id()).isEqualTo(childComment3.getId()), () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), () -> assertThat(response.isOwner()).isFalse() )), From dbc7955eb17dbe0e4bb515e8d6a51fc09981d43f Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Thu, 2 Oct 2025 16:45:59 +0900 Subject: [PATCH 19/21] =?UTF-8?q?test:=20=EC=BB=A8=EB=B2=A4=EC=85=98?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EC=B6=98=20=EC=99=80=EC=9D=BC=EB=93=9C=20?= =?UTF-8?q?=EC=B9=B4=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/service/CommentServiceTest.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java index 5a065d412..86247f775 100644 --- a/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java @@ -1,9 +1,22 @@ package com.example.solidconnection.community.comment.service; +import static com.example.solidconnection.common.exception.ErrorCode.CAN_NOT_UPDATE_DEPRECATED_COMMENT; +import static com.example.solidconnection.common.exception.ErrorCode.INVALID_COMMENT_ID; +import static com.example.solidconnection.common.exception.ErrorCode.INVALID_COMMENT_LEVEL; +import static com.example.solidconnection.common.exception.ErrorCode.INVALID_POST_ACCESS; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + import com.example.solidconnection.common.exception.CustomException; import com.example.solidconnection.community.board.fixture.BoardFixture; import com.example.solidconnection.community.comment.domain.Comment; -import com.example.solidconnection.community.comment.dto.*; +import com.example.solidconnection.community.comment.dto.CommentCreateRequest; +import com.example.solidconnection.community.comment.dto.CommentCreateResponse; +import com.example.solidconnection.community.comment.dto.CommentDeleteResponse; +import com.example.solidconnection.community.comment.dto.CommentUpdateRequest; +import com.example.solidconnection.community.comment.dto.CommentUpdateResponse; +import com.example.solidconnection.community.comment.dto.PostFindCommentResponse; import com.example.solidconnection.community.comment.fixture.CommentFixture; import com.example.solidconnection.community.comment.repository.CommentRepository; import com.example.solidconnection.community.post.domain.Post; @@ -15,19 +28,13 @@ import com.example.solidconnection.siteuser.fixture.UserBlockFixture; import com.example.solidconnection.support.TestContainerSpringBootTest; import jakarta.transaction.Transactional; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import java.util.List; - -import static com.example.solidconnection.common.exception.ErrorCode.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertAll; - @TestContainerSpringBootTest @DisplayName("댓글 서비스 테스트") class CommentServiceTest { @@ -117,7 +124,7 @@ class 댓글_조회_테스트 { () -> assertThat(response.isOwner()).isFalse() )), () -> assertThat(responses) - .extracting("id") + .extracting(PostFindCommentResponse::id) .containsExactly( parentComment.getId(), childComment1.getId(), @@ -218,22 +225,21 @@ class 댓글_조회_테스트 { Comment childComment4 = commentFixture.자식_댓글("자식 댓글1", post, user1, parentComment2); Comment childComment5 = commentFixture.자식_댓글_지연저장("자식 댓글1", post, user1, parentComment2, 2); - // when List responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); // then assertAll( - () -> assertThat(responses).hasSize(3), - () -> assertThat(responses) - .extracting(PostFindCommentResponse::id) - .containsExactly(parentComment1.getId(), childComment1.getId(), childComment3.getId()), - () -> assertThat(responses) - .extracting(PostFindCommentResponse::id) - .doesNotContain(childComment2.getId(), parentComment2.getId(), childComment4.getId(), childComment5.getId()), - () -> assertThat(responses) - .extracting(PostFindCommentResponse::id) - .containsSubsequence(parentComment1.getId(), childComment1.getId(), childComment3.getId()) + () -> assertThat(responses).hasSize(3), + () -> assertThat(responses) + .extracting(PostFindCommentResponse::id) + .containsExactly(parentComment1.getId(), childComment1.getId(), childComment3.getId()), + () -> assertThat(responses) + .extracting(PostFindCommentResponse::id) + .doesNotContain(childComment2.getId(), parentComment2.getId(), childComment4.getId(), childComment5.getId()), + () -> assertThat(responses) + .extracting(PostFindCommentResponse::id) + .containsSubsequence(parentComment1.getId(), childComment1.getId(), childComment3.getId()) ); } } From eb7c63c0b1538cb1bb66de259cdf3db2ac2f8a05 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Thu, 2 Oct 2025 16:47:45 +0900 Subject: [PATCH 20/21] =?UTF-8?q?test:=20=EC=B0=A8=EB=8B=A8=EB=90=9C=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=EC=97=90=EC=84=9C=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A7=80=20=EA=B2=80=EC=A6=9D=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 추가된 메서드: - 차단한_사용자의_게시글은_제외하고_게시글_목록을_최신순으로_조회한다 --- .../post/service/PostQueryServiceTest.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index 054718bc5..f3eaf41a8 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -96,8 +96,8 @@ void setUp() { 6 ); post4 = postFixture.게시글_지연저장( - "제목1", - "내용1", + "제목4", + "내용4", false, PostCategory.자유, boardFixture.자유게시판(), @@ -273,4 +273,36 @@ void setUp() { () -> assertThat(response).extracting(PostListResponse::id).doesNotContain(blockedPost.getId()) ); } + + @Test + void 차단한_사용자의_게시글은_제외하고_게시글_목록을_최신순으로_조회한다() { + // given + SiteUser blockedUser = siteUserFixture.사용자(1, "blockedUser"); + userBlockFixture.유저_차단(user.getId(), blockedUser.getId()); + Board board = boardFixture.자유게시판(); + Post blockedPost = postFixture.게시글(board, blockedUser); + List expectedResponse = List.of(post4, post3, post1); + + // when + List actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc( + BoardCode.FREE.name(), + PostCategory.전체.name(), + user.getId() + ); + + // then + assertAll( + () -> assertThat(actualResponses) + .extracting(PostListResponse::id) + .containsExactlyElementsOf( + expectedResponse.stream() + .map(Post::getId) + .toList() + ), + () -> assertThat(actualResponses) + .extracting(PostListResponse::id) + .doesNotContain(blockedPost.getId()) + ); + + } } From 774e3b29d118782f686d59a74bd083aac05424a1 Mon Sep 17 00:00:00 2001 From: HEX <123macanic@naver.com> Date: Thu, 2 Oct 2025 17:31:33 +0900 Subject: [PATCH 21/21] =?UTF-8?q?chore:=20code=20reformatting=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/common/BaseEntity.java | 9 ++-- .../comment/repository/CommentRepository.java | 48 +++++++++---------- .../post/repository/PostRepository.java | 14 +++--- .../common/helper/TestTimeHelper.java | 2 +- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/example/solidconnection/common/BaseEntity.java b/src/main/java/com/example/solidconnection/common/BaseEntity.java index febf5e77c..b3b597350 100644 --- a/src/main/java/com/example/solidconnection/common/BaseEntity.java +++ b/src/main/java/com/example/solidconnection/common/BaseEntity.java @@ -1,19 +1,18 @@ package com.example.solidconnection.common; +import static java.time.ZoneOffset.UTC; +import static java.time.temporal.ChronoUnit.MICROS; + import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PrePersist; import jakarta.persistence.PreUpdate; +import java.time.ZonedDateTime; import lombok.Getter; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import java.time.ZonedDateTime; - -import static java.time.ZoneOffset.UTC; -import static java.time.temporal.ChronoUnit.MICROS; - @MappedSuperclass @EntityListeners(AuditingEntityListener.class) @Getter diff --git a/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java b/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java index 7d5f2e8b0..4291eb57c 100644 --- a/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java +++ b/src/main/java/com/example/solidconnection/community/comment/repository/CommentRepository.java @@ -12,30 +12,30 @@ public interface CommentRepository extends JpaRepository { @Query(value = """ - WITH RECURSIVE CommentTree AS ( - SELECT - id, parent_id, post_id, site_user_id, content, - created_at, updated_at, is_deleted, - 0 AS level, CAST(id AS CHAR(255)) AS path - FROM comment - WHERE post_id = :postId AND parent_id IS NULL - AND site_user_id NOT IN ( - SELECT blocked_id FROM user_block WHERE blocker_id = :siteUserId - ) - UNION ALL - SELECT - c.id, c.parent_id, c.post_id, c.site_user_id, c.content, - c.created_at, c.updated_at, c.is_deleted, - ct.level + 1, CONCAT(ct.path, '->', c.id) - FROM comment c - INNER JOIN CommentTree ct ON c.parent_id = ct.id - WHERE c.site_user_id NOT IN ( - SELECT blocked_id FROM user_block WHERE blocker_id = :siteUserId - ) - ) - SELECT * FROM CommentTree - ORDER BY path, created_at - """, nativeQuery = true) + WITH RECURSIVE CommentTree AS ( + SELECT + id, parent_id, post_id, site_user_id, content, + created_at, updated_at, is_deleted, + 0 AS level, CAST(id AS CHAR(255)) AS path + FROM comment + WHERE post_id = :postId AND parent_id IS NULL + AND site_user_id NOT IN ( + SELECT blocked_id FROM user_block WHERE blocker_id = :siteUserId + ) + UNION ALL + SELECT + c.id, c.parent_id, c.post_id, c.site_user_id, c.content, + c.created_at, c.updated_at, c.is_deleted, + ct.level + 1, CONCAT(ct.path, '->', c.id) + FROM comment c + INNER JOIN CommentTree ct ON c.parent_id = ct.id + WHERE c.site_user_id NOT IN ( + SELECT blocked_id FROM user_block WHERE blocker_id = :siteUserId + ) + ) + SELECT * FROM CommentTree + ORDER BY path, created_at + """, nativeQuery = true) List findCommentTreeByPostIdExcludingBlockedUsers(@Param("postId") Long postId, @Param("siteUserId") Long siteUserId); default Comment getById(Long id) { diff --git a/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java b/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java index aea6e54a4..cca590270 100644 --- a/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java +++ b/src/main/java/com/example/solidconnection/community/post/repository/PostRepository.java @@ -17,13 +17,13 @@ public interface PostRepository extends JpaRepository { List findByBoardCodeOrderByCreatedAtDesc(String boardCode); @Query(""" - SELECT p FROM Post p - WHERE p.boardCode = :boardCode - AND p.siteUserId NOT IN ( - SELECT ub.blockedId FROM UserBlock ub WHERE ub.blockerId = :siteUserId - ) - ORDER BY p.createdAt DESC - """) + SELECT p FROM Post p + WHERE p.boardCode = :boardCode + AND p.siteUserId NOT IN ( + SELECT ub.blockedId FROM UserBlock ub WHERE ub.blockerId = :siteUserId + ) + ORDER BY p.createdAt DESC + """) List findByBoardCodeExcludingBlockedUsersOrderByCreatedAtDesc(@Param("boardCode") String boardCode, @Param("siteUserId") Long siteUserId); @EntityGraph(attributePaths = {"postImageList"}) diff --git a/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java b/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java index def1dfcb4..c8ca10b3a 100644 --- a/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java +++ b/src/test/java/com/example/solidconnection/common/helper/TestTimeHelper.java @@ -1,12 +1,12 @@ package com.example.solidconnection.common.helper; import com.example.solidconnection.common.BaseEntity; - import java.lang.reflect.Field; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; public class TestTimeHelper { + public static void setCreatedAt(BaseEntity entity, ZonedDateTime time) { try { Field field = BaseEntity.class.getDeclaredField("createdAt");