-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Refactor/#157-comment-repository] 차단 회원의 자식 댓글 조회 막기 #158
Conversation
src/test/java/com/apps/pochak/comment/domain/repository/CommentRepositoryTest.java
Outdated
Show resolved
Hide resolved
memberRepository.save(POST_OWNER); | ||
memberRepository.save(PARENT_COMMENTER); | ||
memberRepository.save(CHILD_COMMENTER); | ||
Member loginMember = memberRepository.save(LOGIN_MEMBER); |
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.
memberRepository.save(POST_OWNER);
memberRepository.save(PARENT_COMMENTER);
memberRepository.save(CHILD_COMMENTER);
Member loginMember = memberRepository.save(LOGIN_MEMBER);
이 부분 모든 곳에서 겹치니 따로 beforeeach 같은걸로 묶어도 될 것 같아요
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.
아 이게 변수에 저장해서 써야할 것 들이 있어서 beforeeach에서 묶고 find조회해서 쓰는 게 나을까요?
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.
class BlockServiceTest extends ServiceTest {
// ...
private Member owner;
private Member taggedMember1;
private Member taggedMember2;
private Member loginMember;
@BeforeEach
void setUp() {
owner = memberRepository.save(OWNER);
taggedMember1 = memberRepository.save(TAGGED_MEMBER1);
taggedMember2 = memberRepository.save(TAGGED_MEMBER2);
loginMember = memberRepository.save(LOGIN_MEMBER);
}
전 이런식으로 하고 있는데 어떤가요?!
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.
이 방식으로 수정했습니다~
memberRepository.deleteAll(); | ||
tagRepository.deleteAll(); | ||
blockRepository.deleteAll(); | ||
} |
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.
이거 상단에 @transactional 붙여줘서 필요없지 않나요?
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.
getComments()가 지금 걱정되는데 여기도 부모 댓글 + 그 각각의 자식댓글 조회인데,,
여기서 그 각각의 자식 댓글을 조회할 때 차단 로직도 잘 적용되나요?
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.
아 getComments()에도 추가해야 할 것 같아요
@Query(value = "SELECT filtered.* " + | ||
"FROM ( " + | ||
" SELECT c.*, " + | ||
" ROW_NUMBER() OVER (PARTITION BY c.parent_comment_id ORDER BY c.created_date ASC) AS row_num " + |
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.
테스트가
- 자식 댓글 조회 - 정상 테스트
- 자식 댓글 조회 - 자식 댓글 작성자에게 차단됐을때
- 부모 댓글 조회 - 정상 테스트
- 부모 댓글 조회 - 부모 댓글 작성자를 차단했을 때
- 자식 댓글 조회 - 정상 테스트
- 자식 댓글 조회 - 자식 댓글 작성자를 차단했을 때
이렇게같은데
자식 / 부모 댓글 정렬.. 한번만 맞춰주시면서 @DisplayName에 설명 조금만 추가해도 좋을 것 같아요 (조금.. 헷갈림,,ㅎㅎ) -> (아니면 메소드 순서에 다른 뜻이 있었나요?)
@@ -20,12 +22,25 @@ public class CommentElements { | |||
private String loginMemberProfileImage; | |||
|
|||
public CommentElements( | |||
final Member loginMember, final Page<Comment> parentCommentPage | |||
final Member loginMember, final Page<Comment> parentCommentPage, final List<Comment> childComments |
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.
다른 코드와의 통일성을 위해,, 엔터 한번씩 쳐도 좋을 것 같아요ㅎㅎ
final Page<Comment> commentList = commentRepository.findParentCommentByPost(post, loginMember, pageable); | ||
return new CommentElements(loginMember, commentList); | ||
final Page<Comment> parentCommentList = commentRepository.findParentCommentByPost(post, loginMember, pageable); | ||
final List<Comment> childCommentList = commentRepository.findChildCommentByParentComments(parentCommentList.stream().map(Comment::getId).toList(), loginMember.getId()); |
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.
요기두용 intellij 로 켜서 보니까 너무 긴 것 같기두..?!
for (Comment parentComment : parentCommentPage.getContent()) { | ||
List<Comment> childCommentList = new ArrayList<>(); | ||
for (Comment childComment : childComments) { | ||
if (Objects.equals(parentComment.getId(), childComment.getParentComment().getId())) { |
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.
오 그냥 equals()랑 뭐가 다른지 찾아보니까 이건 npe가 방지되는군여
} | ||
} | ||
parentCommentList.add(new ParentCommentElement(parentComment, childCommentList)); | ||
} |
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.
굿 이렇게 조립하는게 제일 깔끔할 것 같아요 어차피 페이징 덕에 큰 데이터를 끌고 오는 것도 아니라서 👍
" and ?2 not in (select b.blocked_id from block b where b.blocker_id = c.member_id) " + | ||
") child_comments " + | ||
"where child_comments.row_num <= 30", nativeQuery = true) | ||
List<Comment> findChildCommentByParentComments(List<Long> parentCommentIds, Long loginMemberId); |
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.
아 ㅋㅋㅋㅋㅋㅋ 다른 코드 쓸때 """ < 이걸 몰랐어서 안썼던 거에요ㅎ;; 그냥 써도 될 것 같아요..허허
API 순서대로 했던 거 같아요 위에는 getComments() 밑에는 답글 조회 ..! 설명 추가하겠습니다 |
sonarqubecloud issue 중에서 고칠만한건 없으셨나요?! |
…U-POCHAK/POCHAK-Server into test/#157-comment-repository
|
|
📒 개요
차단 회원의 자식 댓글 조회 막기
📍 Issue 번호
🛠️ 작업사항
🧰 추가 논의사항