Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- BFS
- 코드트리
- 알고리즘
- 트러블슈팅
- Java
- 코딩테스트
- 완탐
- Spring
- 알고리즘기본개념
- 완전탐색
- DP
- 기본유형
- JUnit
- SSAFY
- SWEA
- database
- 유니온파인드
- 다시보기
- 코딩테스트실력진단
- 부분수열의합2
- 코테
- DFS
- Union Find
- 자바
- 그리디
- 다익스트라
- 백준
- 그래프
- JPA
- 싸피
Archives
- Today
- Total
HwangHub
[리팩토링] 대댓글 생성시, 댓글 id만 받고, postid는 댓글 id에서 뽑기 본문
PROJECT-LOG/likelion.university
[리팩토링] 대댓글 생성시, 댓글 id만 받고, postid는 댓글 id에서 뽑기
HwangJerry 2023. 10. 13. 16:32기존 구현
postId와 parentCommentId를 둘 다 body로 받아서 대댓글 생성.
문제점
parentComment가 가진 postId와 childComment가 가진 postId가 불일치하진 않는지 체크해야 한다. 이는 불필요한 로직을 추가적으로 양산하며, 클라이언트가 postId까지 신경쓰도록 반영해야 하므로 서버에서 parentComment가 가진 postId를 뽑아서 반영해주는 로직이 더 깔끔할 것이라 보았다.
결과 로직
private Comment childCommentBy(CommentCreateChildServiceDto request) {
Comment comment = Comment.builder()
.post(getPostFromParentComment(request))
.author(userAdaptor.findById(request.getLoginUserId()))
.body(request.getBody())
.build();
comment.setParent(parentCommentBy(request.getParentCommentId()));
return comment;
}
private Post getPostFromParentComment(CommentCreateChildServiceDto request) {
return commentAdaptor.findById(request.getParentCommentId()).getPost();
}
'PROJECT-LOG > likelion.university' 카테고리의 다른 글
[이슈] SQL로 DB 스키마 변경 (1) | 2023.12.31 |
---|---|
[설계] 프로젝트 아키텍처로 멀티 모듈을 선택한 이유 (0) | 2023.10.22 |
[이슈] 게시글별 댓글 전체 조회시 대댓글 개수만큼 부모 댓글만 중복 조회됨 (0) | 2023.10.13 |
[이슈] Field 'id' doesn't have a default value (0) | 2023.10.13 |
[리팩토링] post 엔티티 body 필드 TEXT 적용 (0) | 2023.10.13 |
Comments