diff --git a/back/src/main/java/com/back/domain/post/comment/controller/PostCommentController.java b/back/src/main/java/com/back/domain/post/comment/controller/PostCommentController.java index fe15ae4b..95bbce0b 100644 --- a/back/src/main/java/com/back/domain/post/comment/controller/PostCommentController.java +++ b/back/src/main/java/com/back/domain/post/comment/controller/PostCommentController.java @@ -28,7 +28,7 @@ public class PostCommentController { private final Rq rq; private final PostCommentService postCommentService; - @Operation(summary = "댓글 생성") + @Operation(summary = "댓글 생성", description = "comment는 공백이나 Null이 될 수 없습니다. comment의 글자 수 제한은 없습니다.") @PostMapping("/post/{post_id}") public RsData createComment(@PathVariable Long post_id, @Valid @RequestBody CommentCreateRequest commentCreateRequest @@ -41,13 +41,12 @@ public RsData createComment(@PathVariable Long post_id, @Operation(summary = "댓글 다건 조회") @GetMapping("/post/{post_id}") - @Transactional(readOnly = true) public RsData> getAllPostComment(@PathVariable Long post_id) { List postAllResponse = postCommentService.getAllPostCommentResponse(post_id); - return new RsData<>("200", "게시글 다건 조회 성공", postAllResponse); + return new RsData<>("200", "댓글 조회 성공", postAllResponse); } - @Operation(summary = "댓글 삭제") + @Operation(summary = "댓글 삭제", description = "commentId는 공백이나 Null이 될 수 없습니다.") @DeleteMapping("/post/{post_id}/comment") public RsData removePostComment(@PathVariable @Positive Long post_id , @RequestBody @Valid CommentDeleteRequest commentDeleteRequest) { @@ -55,10 +54,10 @@ public RsData removePostComment(@PathVariable @Positive Long post_id postCommentService.removePostComment(post_id, commentDeleteRequest, member); - return new RsData<>("200", "게시글 삭제 성공", null); + return new RsData<>("200", "댓글 삭제 성공", null); } - @Operation(summary = "댓글 수정") + @Operation(summary = "댓글 수정", description = "commentId, content는 공백이나 Null이 될 수 없습니다. content의 글자 수 제한은 없습니다. ") @PutMapping("/post/{post_id}/comment/") public RsData updatePostComment(@PathVariable Long post_id , @Valid @RequestBody CommentModifyRequest commentModifyRequest) { diff --git a/back/src/main/java/com/back/domain/post/comment/dto/CommentCreateRequest.java b/back/src/main/java/com/back/domain/post/comment/dto/CommentCreateRequest.java index 4cb485be..c65855ba 100644 --- a/back/src/main/java/com/back/domain/post/comment/dto/CommentCreateRequest.java +++ b/back/src/main/java/com/back/domain/post/comment/dto/CommentCreateRequest.java @@ -4,8 +4,6 @@ public record CommentCreateRequest( - String role, - @NotBlank(message = "댓글을 입력해주세요") String comment ) { diff --git a/back/src/main/java/com/back/domain/post/comment/service/PostCommentService.java b/back/src/main/java/com/back/domain/post/comment/service/PostCommentService.java index aec768a2..fddecd73 100644 --- a/back/src/main/java/com/back/domain/post/comment/service/PostCommentService.java +++ b/back/src/main/java/com/back/domain/post/comment/service/PostCommentService.java @@ -27,6 +27,10 @@ public class PostCommentService { public void createComment(Member member, Long postId, CommentCreateRequest commentCreateRequest) { Post post = postRepository.findById(postId).orElseThrow(() -> new ServiceException("400", "해당 Id의 게시글이 없습니다.")); + if ( commentCreateRequest.comment() == null || commentCreateRequest.comment().isEmpty()) { + throw new ServiceException("400", "댓글은 비어 있을 수 없습니다."); + } + PostComment postComment = PostComment.builder() .post(post) .content(commentCreateRequest.comment()) diff --git a/back/src/test/java/com/back/domain/post/comment/PostCommentControllerTest.java b/back/src/test/java/com/back/domain/post/comment/PostCommentControllerTest.java index 017ab35a..21dfb001 100644 --- a/back/src/test/java/com/back/domain/post/comment/PostCommentControllerTest.java +++ b/back/src/test/java/com/back/domain/post/comment/PostCommentControllerTest.java @@ -142,7 +142,7 @@ void t3() throws Exception { .andExpect(handler().methodName("getAllPostComment")) .andExpect(status().isOk()) .andExpect(jsonPath("$.data").isArray()) - .andExpect(jsonPath("$.msg").value("게시글 다건 조회 성공")) + .andExpect(jsonPath("$.msg").value("댓글 조회 성공")) .andExpect(jsonPath("$.data").exists()) .andExpect(jsonPath("$.data", hasSize(greaterThan(0)))); @@ -186,7 +186,7 @@ void t4() throws Exception { .andExpect(handler().handlerType(PostCommentController.class)) .andExpect(handler().methodName("removePostComment")) .andExpect(jsonPath("$.resultCode").value("200")) - .andExpect(jsonPath("$.msg").value("게시글 삭제 성공")); + .andExpect(jsonPath("$.msg").value("댓글 삭제 성공")); } @Test diff --git a/back/src/test/java/com/back/domain/post/comment/service/PostCommentServiceTest.java b/back/src/test/java/com/back/domain/post/comment/service/PostCommentServiceTest.java index 22f1134d..7a478265 100644 --- a/back/src/test/java/com/back/domain/post/comment/service/PostCommentServiceTest.java +++ b/back/src/test/java/com/back/domain/post/comment/service/PostCommentServiceTest.java @@ -50,7 +50,7 @@ void createComment_success() { Member member = MemberFixture.create(1L, "user@test.com", "User", "password", Member.Role.MENTEE); Post post = createDefaultPost(member); Long postId = 1L; - CommentCreateRequest request = new CommentCreateRequest("MENTEE","테스트 댓글"); + CommentCreateRequest request = new CommentCreateRequest("테스트 댓글"); when(postRepository.findById(postId)).thenReturn(Optional.of(post)); when(postCommentRepository.save(any(PostComment.class))).thenReturn(any(PostComment.class)); @@ -69,7 +69,7 @@ void createComment_postNotExists_failure() { // given Member member = MemberFixture.createDefault(); Long postId = 999L; - CommentCreateRequest request = new CommentCreateRequest("MENTEE","테스트 댓글"); + CommentCreateRequest request = new CommentCreateRequest("테스트 댓글"); when(postRepository.findById(postId)).thenReturn(Optional.empty());