-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat #22 Reply-기능-개발 #24
The head ref may contain hidden characters: "feat/#22/\uC778\uC6A9-\uB9AC\uD2B8\uC717\uB85C\uC9C1-\uAC1C\uBC1C"
Conversation
PR 멘트 中 답글과 글 나중에 추가될 리트윗도 결국, 같은 Post엔티티를 사용하기에 나타나는 문제를 지적해주셨습니다. 동감합니다 강혁님과 이야기 논의 해서 결정하시는게 좋다고 생각합니다! |
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.
현재 DTO에서 하는 일이 너무 많은 것 같아요
withoutReplies가 하는 역할을 service 단으로 분리하고, 해당 DTO를 만드는 메서드는 from
만 사용을 하는게 좋아 보여요!
DTO가 Data Transfer Object 이니 데이터를 옮기는 역할에 더 집중하면 좋을 것 같아요!
|
||
|
||
// Post 객체를 PostResponseDto로 변환하여 반환 | ||
return posts.stream() |
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.
PostResponseDto에서 부모 글들만 조회를 하는 경우 withoutReplies 메서드를 사용 했는데, DB에서 findByParentIsNullAndIsDeletedOrderByCreatedAtDesc로 조회를 해오면 부모 글만 조회가 돼서 withoutReplies 메서드로 DTO를 만들지 않아도 될 것 같아요!
하나의 DTO 생성 메서드를 사용하되, 서비스 단에서 로직을 통해 부모글만 조회, 자식 글 까지 상세 조회.를 나눠서 구현하는 것은 어떨까요??
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.
업 근데, findByParentIsNullAndIsDeletedOrderByCreatedAtDesc로 조회를 해오면 부모 글뿐만아니라 답글까지 딸려나와서 withoutReplies로 함께 써야 나오지 않아서 사용하였습니다!
.map(PostResponseDto::from) // DTO로 변환 | ||
.filter(post -> post.getIsDeleted() == IsDeleted.ACTIVE) | ||
.sorted(Comparator.comparing(Post::getLikesCount).reversed()) | ||
.map(post -> PostResponseDto.from(post, user, likeRepository)) // 좋아요 여부 반영 |
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.
좋아요 여부를 체크하는 것은 dto에서 하기 보다 서비스 단에서 하고, boolean 객체를 넘겨서 그대로 넣는 것도 좋아 보여요!
postRepository.save(post); | ||
|
||
// 좋아요 수 갱신 | ||
updateLikecount(post); |
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.
빠른 반영 좋아요 👍🏻👍🏻
@@ -157,4 +200,16 @@ public PostUserResponse findUser(String email) { | |||
User user = userService.find(email); | |||
return PostUserResponse.from(user); // PostUserResponse로 변환하여 반환 | |||
} | |||
|
|||
private Post createPost(PostRequestDTO postRequestDTO, User user, Post parentPost) { |
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.
Post를 만드는 메서드는 Post 객체 안에 static 팩토리 메서드로 구현해서 숨겨서 구현하면 캡슐화를 구현할 수 있어서 좋을 것 같아요!
# Conflicts: # src/main/java/com/leets/X/domain/post/service/PostService.java
1. 무슨 이유로 코드를 변경했나요?
X의 Reply 기능을 구현하였습니다.
Reply(답글) 기능은 post와 비슷한 양상을 가지는데,
답글을 생성하면 글을 생성하는 것과 비슷하게 post_id가 생성이 됩니다. 하나 이 id는 답글을 구분하는 id이고
답글의 답글 즉, 다 답글은 parent 글의 id에 답글을 다는 것이 아닌, 답글의 id에 답글을 다는 것이라고 이해해야 합니다.
하나의 post에 대해서 답글을 꼬리 물어다는 것도 가능하고, post에 하나의 답글 씩 다는 것도 가능합니다.
2. 어떤 위험이나 장애를 발견했나요?
현재 게시글 삭제 로직이 soft delete 이므로 (상태만 삭제임을 드러냄) , 답글 삭제도 마찬가지로 상태만 삭제됨을 나타낼 수 있습니다. 이에따라 조회를 하면 나머지 데이터들이 함께 조회될 수 있습니다.
또한 , 답글을 post로 인식하기 때문에 최신 게시물 조회같은 요청이 들어오면 게시물이 아닌 답글이 조회되는 상황이 있습니다. (수정 중 입니다.)
-> 위는 Post Type을 나타내는 enum타입을 사용할지 , 아니면 Parent의 값이 null이면 일반 글, 아니면 답글 이렇게 구분할지 더 좋은 아이디어 있으면 피드백 부탁드립니다!
3. 관련 스크린샷을 첨부해주세요.
4. 완료 사항
답글 기능(서비스, 컨트롤러, Dto, post매핑 , ResponseMessage)
5. 추가 사항
추가적으로 CRUD 로직에 에러메시지나 , 통일이 필요한 부분들을 리팩토링 할 예정입니다.