-
Notifications
You must be signed in to change notification settings - Fork 8
fix: PostRepository & CommentRepository의 일부 메서드의 정렬 순서 오류 해결 #522
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
Changes from 15 commits
0633ef1
89b0d95
6e164c6
a61e8ae
8394ca0
7120341
c1344f6
ec76fad
563c71d
920002e
d6ba7be
a607431
f45446a
6edde9b
58b8bdf
244b292
6b561f7
e193241
dbc7955
eb7c63c
774e3b2
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 |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ WHERE c.site_user_id NOT IN ( | |
| ) | ||
| ) | ||
| SELECT * FROM CommentTree | ||
| ORDER BY path | ||
| ORDER BY path, created_at | ||
|
Contributor
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. 전 이 path가 문자열이라서 사전식 정렬로 인한 문제가 된다고 늘 생각했었는데 이렇게 간단하게 해결이 되는군요!
Contributor
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. 차단 유저가 있는 경우에도 이 순서가 잘 지켜지는 테스트 코드가 있으면 좋겠습니다!
Contributor
Author
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. 추가해보겠습니다!
Contributor
Author
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. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chain정렬 방향(ASC/DESC)을 명시해주세요.
다음 스크립트로 PostRepository의 정렬 방향과 일관성을 확인해보세요: 🏁 Script executed: #!/bin/bash
# Description: PostRepository의 createdAt 정렬 방향 확인 및 CommentRepository와 비교
echo "=== PostRepository의 ORDER BY 절 확인 ==="
rg -n "ORDER BY.*createdAt" src/main/java/com/example/solidconnection/community/post/repository/
echo -e "\n=== CommentRepository의 ORDER BY 절 확인 ==="
rg -n "ORDER BY" src/main/java/com/example/solidconnection/community/comment/repository/Length of output: 341 정렬 방향을 명시해 주세요. 변경 내용을 한눈에 확인하려면:
원하는 순서에 따라 아래처럼 수정하세요:
🤖 Prompt for AI Agents |
||
| """, nativeQuery = true) | ||
| List<Comment> findCommentTreeByPostIdExcludingBlockedUsers(@Param("postId") Long postId, @Param("siteUserId") Long siteUserId); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()); | ||
|
Member
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. 어라 이거도 레거시같은데
Contributor
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. 여기서 같이 제거해도 될 거 같습니다! 7월에 반영된 거 같은데 놓쳤네요..
Contributor
Author
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. 넵 반영하겠습니다! |
||
|
|
||
| Comment saved = commentRepository.save(comment); | ||
|
|
||
| TestTimeHelper.setCreatedAt(saved, saved.getCreatedAt().plusSeconds(seconds)); | ||
|
|
||
| return commentRepository.save(saved); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,15 +82,19 @@ void setUp() { | |
| class 댓글_조회_테스트 { | ||
|
|
||
| @Test | ||
| void 게시글의_모든_댓글을_조회한다() { | ||
| void 게시글의_모든_댓글과_대댓글을_생성시간_기준으로_정렬해_조회한다() { | ||
| // given | ||
| Comment parentComment = commentFixture.부모_댓글("부모 댓글", post, user1); | ||
| Comment childComment = commentFixture.자식_댓글("자식 댓글 1", post, user2, parentComment); | ||
| List<Comment> comments = List.of(parentComment, childComment); | ||
| Comment childComment1 = commentFixture.자식_댓글("자식 댓글 1", post, user2, parentComment); | ||
| Comment childComment2 = commentFixture.자식_댓글_지연저장("자식 댓글 2", post, user1, parentComment, 3); | ||
| Comment childComment3 = commentFixture.자식_댓글_지연저장("자식 댓글 3", post, user2, parentComment, 5); | ||
| List<Comment> comments = List.of(parentComment, childComment1, childComment2, childComment3); | ||
|
|
||
| // when | ||
| List<PostFindCommentResponse> responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); | ||
|
|
||
| System.out.println(responses); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
Member
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. 여기 디버깅문 있습니다 !
Contributor
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. 이전 커밋들에서도 계속 이걸 작성하고 제거하신 거 같은데요!
Contributor
Author
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. 넵 중단점 습관화를 한 번 도전해볼게요! |
||
|
|
||
| // then | ||
| assertAll( | ||
| () -> assertThat(responses).hasSize(comments.size()), | ||
|
Member
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. 마지막에
Contributor
Author
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. 넵 반영하겠습니다! |
||
|
|
@@ -103,13 +107,37 @@ 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(childComment.getId()), | ||
| () -> assertThat(response.id()).isEqualTo(childComment1.getId()), | ||
|
Member
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. 레거시 코드 같긴 하지만,
Contributor
Author
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. 넵 확인했습니다! |
||
| () -> 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(childComment3.getId()), | ||
| () -> assertThat(response.parentId()).isEqualTo(parentComment.getId()), | ||
| () -> assertThat(response.isOwner()).isFalse() | ||
| )), | ||
| () -> assertThat(responses) | ||
| .extracting("id") | ||
|
Contributor
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. 제가 예시를 너무 간단히 드렸던거긴 한데.. 지금 와서 보니 as is
to be
이게 조금더 나을 거 같기도 하네요! 반영 안해주셔도 괜찮습니다!
Contributor
Author
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. 반영하겠습니다! |
||
| .containsExactly( | ||
| parentComment.getId(), | ||
| childComment1.getId(), | ||
| childComment2.getId(), | ||
| childComment3.getId() | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -198,24 +226,28 @@ 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 | ||
| List<PostFindCommentResponse> responses = commentService.findCommentsByPostId(user1.getId(), post.getId()); | ||
|
|
||
| // then | ||
| assertAll( | ||
| () -> assertThat(responses).hasSize(2), | ||
| () -> assertThat(responses).hasSize(3), | ||
| () -> assertThat(responses) | ||
| .extracting(PostFindCommentResponse::id) | ||
| .containsExactly(parentComment1.getId(), childComment1.getId(), childComment3.getId()), | ||
| () -> assertThat(responses) | ||
| .extracting(PostFindCommentResponse::id) | ||
| .containsExactly(parentComment1.getId(), childComment1.getId()), | ||
| .doesNotContain(childComment2.getId(), parentComment2.getId(), childComment4.getId(), childComment5.getId()), | ||
| () -> assertThat(responses) | ||
| .extracting(PostFindCommentResponse::id) | ||
| .doesNotContain(childComment2.getId(), parentCommen2.getId(), childComment3.getId(), childComment4.getId()) | ||
| .containsSubsequence(parentComment1.getId(), childComment1.getId(), childComment3.getId()) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
|
@@ -74,4 +75,22 @@ public Post create() { | |
| post.setBoardAndSiteUserId(board.getCode(), siteUser.getId()); | ||
| return postRepository.save(post); | ||
| } | ||
|
|
||
| public Post createWithDelaySeconds(long seconds) { | ||
| Post post = new Post( | ||
| title, | ||
| content, | ||
| isQuestion, | ||
| likeCount, | ||
| viewCount, | ||
| postCategory); | ||
| post.setBoardAndSiteUserId(board.getCode(), siteUser.getId()); | ||
|
|
||
| Post saved = postRepository.save(post); | ||
|
|
||
| System.out.println(saved); | ||
|
Member
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. 여기도 디버깅 있습니다 !
Contributor
Author
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. 넵 확인했습니다! |
||
|
|
||
| TestTimeHelper.setCreatedAt(saved, saved.getCreatedAt().plusSeconds(seconds)); | ||
| return postRepository.save(post); | ||
| } | ||
|
Comment on lines
+78
to
+93
Contributor
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. 이것두요!
Contributor
Author
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 comment
The reason will be displayed to describe this comment to others. Learn more.
미사용 import문 제거해주세요 ! 인텔리제이 사용하시면 설정을 통해 자동 삭제 가능합니다.
Uh oh!
There was an error while loading. Please reload this page.
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.
참고로 reformat code 적용해도 알아서 제거 해주긴 합니다~
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.
오 이런 편리한 기능이... 실수할 일이 적어질 것 같네요! 감사합니다~