Conversation
Martinel2
left a comment
There was a problem hiding this comment.
2주차 과제 수고하셨습니다!! 코드도 굉장히 완성도가 높고, 테스트코드도 통합 테스트 코드로 잘 작성해주신 것 같네요.
더 해볼 것이 있다면, 사용자 스토리를 먼저 작성 한 뒤, 테스트를 하나의 기능만을(ex)서비스단의 특정 메서드만)을 테스트하는 코드를 먼저 작성해보는 것을 추천드려요!!
그 후, 해당 테스트를 통과하도록 기능을 하나씩 구현하고, 최종적으로 통합테스트까지 통과하게되면, 그 유명한 TDD 방식을 사용하여 코드를 작성하실 수 있습니다
| @Builder | ||
| private Comment(String content, Post post) { | ||
| this.content = content; | ||
| this.post = post; | ||
| } |
There was a problem hiding this comment.
Setter가 아닌 Builder를 사용하는 방식 아주 좋습니다!
| import java.util.List; | ||
|
|
||
| @Service | ||
| public class CommentService { |
There was a problem hiding this comment.
DB를 건드리는 코드이니 @transactional을 통하여 트랜잭션을 설정해두면 좋을 것 같아요!!
|
|
||
| public Comment create(Long postId, String content) { | ||
| Post post = postRepo.findById(postId) | ||
| .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Post not found")); |
There was a problem hiding this comment.
해당 코드는 아래에 작성한 ensurePostExists와 어떤 차이점이 존재할까요?
| Post post = repo.findById(id) | ||
| .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Post not found")); |
There was a problem hiding this comment.
commentService에서도 같은 방식이 존재하는데, 이러한 코드 중복은 어떻게 처리하는 것이 좋을까요?
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/posts/{postId}/comments") |
There was a problem hiding this comment.
comment를 설정하는 모든 코드에서 postId가 필수로 존재해야할까요? 그렇다면 왜 그렇게해야할까요? 아니라면 어떤식으로 코드를 수정할 수 있을까요?
|
|
||
| @ResponseStatus(HttpStatus.CREATED) | ||
| @PostMapping | ||
| public PostResponse create(@Valid @RequestBody PostCreateRequest req) { |
| public record CommentResponse( | ||
| Long id, | ||
| String content | ||
| ) { | ||
| public static CommentResponse from(Comment c) { | ||
| return new CommentResponse(c.getId(), c.getContent()); | ||
| } | ||
| } |
변경점 👍
setter취약점 변경, 댓글 기능 추가, 테스트 코드 추가
버그 해결 💊
해결한 버그
테스트 💻
변경점을 테스트하기 위한 방법 기술
스크린샷 🖼
변경된 부분에 대한 스크린샷
비고 ✏
리뷰어에게 전하는 말 등
사용하지 않은 항목은 모두 지워주세요.