이번 강의는 앞에서 구현했던 글 수정 API를 그대로 확장해서
댓글 수정 API를 구현하는 강의였다.
구조도 흐름도 이미 익숙한 패턴이라
“아, 이제 이건 손에 익었다”는 느낌이 드는 단계다.
@RequestBody@ValidRsData<Void>record PostCommentModifyReqBody(
@NotBlank
@Size(min = 2, max = 100)
String content
) {
}
📌 댓글 수정은 content 하나만 바뀌므로
DTO도 그에 맞게 최소한으로 구성한다.
@PutMapping("/{id}")
@Transactional
public RsData<Void> modify(
@PathVariable int postId,
@PathVariable int id,
@Valid @RequestBody PostCommentModifyReqBody reqBody
) {
Post post = postService.findById(postId).get();
PostComment postComment = post.findCommentById(id).get();
postService.modifyComment(postComment, reqBody.content);
return new RsData<>(
"200-1",
"%d번 댓글이 수정되었습니다.".formatted(id)
);
}
Post post = postService.findById(postId).get();
PostComment postComment = post.findCommentById(id).get();
👉 이 구조의 장점
postService.modifyComment(postComment, reqBody.content);
return new RsData<>(
"200-1",
"%d번 댓글이 수정되었습니다.".formatted(id)
);
RsData<Void>200 OK 가 가장 자연스럽다201 Created 는 생성일 때만 사용이제는 새로운 API를 봐도
“어디서 DTO 만들고,
어디서 서비스 호출하고,
어떤 RsData를 반환할지”
머릿속에 바로 그려진다.
이 단계부터는
👉 기능 추가보다 설계 감각이 쌓이는 구간이라는 느낌이 든다.