-
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 20 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 | ||
|
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; | ||
|
|
@@ -46,8 +47,18 @@ 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.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 |
|---|---|---|
| @@ -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,20 @@ 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); | ||
|
|
||
| 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.
전 이 path가 문자열이라서 사전식 정렬로 인한 문제가 된다고 늘 생각했었는데 이렇게 간단하게 해결이 되는군요!
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.
차단 유저가 있는 경우에도 이 순서가 잘 지켜지는 테스트 코드가 있으면 좋겠습니다!
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.
추가해보겠습니다!
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.
반영했습니다!