From a82704374c862236c8c8a21b8085228c0addb64d Mon Sep 17 00:00:00 2001 From: woo-chang Date: Fri, 28 Jul 2023 14:45:37 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20(#131)=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=EC=9E=90,=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/entity/comment/Comment.java | 15 +++++ .../post/exception/CommentExceptionType.java | 5 +- .../post/entity/comment/CommentTest.java | 67 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/votogether/domain/post/entity/comment/Comment.java b/backend/src/main/java/com/votogether/domain/post/entity/comment/Comment.java index e08724290..94fe03637 100644 --- a/backend/src/main/java/com/votogether/domain/post/entity/comment/Comment.java +++ b/backend/src/main/java/com/votogether/domain/post/entity/comment/Comment.java @@ -3,6 +3,8 @@ import com.votogether.domain.common.BaseEntity; import com.votogether.domain.member.entity.Member; import com.votogether.domain.post.entity.Post; +import com.votogether.domain.post.exception.CommentExceptionType; +import com.votogether.exception.BadRequestException; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -11,6 +13,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import java.util.Objects; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -45,4 +48,16 @@ private Comment(final Post post, final Member member, final String content) { this.content = new Content(content); } + public void validateWriter(final Member member) { + if (!Objects.equals(this.member.getId(), member.getId())) { + throw new BadRequestException(CommentExceptionType.NOT_WRITER); + } + } + + public void validateBelong(final Post post) { + if (!Objects.equals(this.post.getId(), post.getId())) { + throw new BadRequestException(CommentExceptionType.NOT_BELONG_POST); + } + } + } diff --git a/backend/src/main/java/com/votogether/domain/post/exception/CommentExceptionType.java b/backend/src/main/java/com/votogether/domain/post/exception/CommentExceptionType.java index eadbe1df0..e635a99a4 100644 --- a/backend/src/main/java/com/votogether/domain/post/exception/CommentExceptionType.java +++ b/backend/src/main/java/com/votogether/domain/post/exception/CommentExceptionType.java @@ -6,7 +6,10 @@ @Getter public enum CommentExceptionType implements ExceptionType { - INVALID_CONTENT_LENGTH(2000, "유효하지 않은 댓글 길이입니다."); + INVALID_CONTENT_LENGTH(2000, "유효하지 않은 댓글 길이입니다."), + COMMENT_NOT_FOUND(2001, "해당 댓글이 존재하지 않습니다."), + NOT_BELONG_POST(2002, "댓글의 게시글 정보와 일치하지 않습니다."), + NOT_WRITER(2003, "댓글 작성자가 아닙니다."); private final int code; private final String message; diff --git a/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java b/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java index 70f6c2116..07ac1bd42 100644 --- a/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java +++ b/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.votogether.domain.member.entity.Member; import com.votogether.domain.post.entity.Post; import com.votogether.domain.post.entity.PostBody; import com.votogether.exception.BadRequestException; @@ -9,6 +10,7 @@ import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.test.util.ReflectionTestUtils; class CommentTest { @@ -39,4 +41,69 @@ void invalidContentLength() { .hasMessage("유효하지 않은 댓글 길이입니다."); } + @Test + @DisplayName("댓글 작성자가 아니라면 예외를 던진다.") + void invalidWriter() { + // given + Member member = MemberFixtures.FEMALE_20.get(); + PostBody body = PostBody.builder() + .title("title") + .content("content") + .build(); + Post post = Post.builder() + .member(member) + .postBody(body) + .deadline(LocalDateTime.now()) + .build(); + Comment comment = Comment.builder() + .member(member) + .post(post) + .content("content") + .build(); + + ReflectionTestUtils.setField(member, "id", 1L); + + // when, then + assertThatThrownBy(() -> comment.validateWriter(MemberFixtures.MALE_20.get())) + .isInstanceOf(BadRequestException.class) + .hasMessage("댓글 작성자가 아닙니다."); + } + + @Test + @DisplayName("작성되어 있는 게시글이 아니라면 예외를 던진다.") + void invalidPost() { + // given + Member member = MemberFixtures.FEMALE_20.get(); + PostBody bodyA = PostBody.builder() + .title("title") + .content("content") + .build(); + Post postA = Post.builder() + .member(member) + .postBody(bodyA) + .deadline(LocalDateTime.now()) + .build(); + PostBody bodyB = PostBody.builder() + .title("title") + .content("content") + .build(); + Post postB = Post.builder() + .member(member) + .postBody(bodyB) + .deadline(LocalDateTime.now()) + .build(); + Comment comment = Comment.builder() + .member(member) + .post(postA) + .content("content") + .build(); + + ReflectionTestUtils.setField(postA, "id", 1L); + + // when, then + assertThatThrownBy(() -> comment.validateBelong(postB)) + .isInstanceOf(BadRequestException.class) + .hasMessage("댓글의 게시글 정보와 일치하지 않습니다."); + } + } From a000be681a20820ef81a78e3c8ae68cbc5ad63e0 Mon Sep 17 00:00:00 2001 From: woo-chang Date: Fri, 28 Jul 2023 14:55:54 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20(#131)=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/service/PostCommentService.java | 16 +++ .../post/service/PostCommentServiceTest.java | 126 ++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java index 1550fda38..dc5edfade 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java @@ -4,7 +4,9 @@ import com.votogether.domain.post.dto.request.CommentRegisterRequest; import com.votogether.domain.post.entity.Post; import com.votogether.domain.post.entity.comment.Comment; +import com.votogether.domain.post.exception.CommentExceptionType; import com.votogether.domain.post.exception.PostExceptionType; +import com.votogether.domain.post.repository.CommentRepository; import com.votogether.domain.post.repository.PostRepository; import com.votogether.exception.NotFoundException; import lombok.RequiredArgsConstructor; @@ -16,6 +18,7 @@ public class PostCommentService { private final PostRepository postRepository; + private final CommentRepository commentRepository; @Transactional public void createComment( @@ -34,4 +37,17 @@ public void createComment( post.addComment(comment); } + @Transactional + public void deleteComment(final Member member, final Long postId, final Long commentId) { + final Post post = postRepository.findById(postId) + .orElseThrow(() -> new NotFoundException(PostExceptionType.POST_NOT_FOUND)); + final Comment comment = commentRepository.findById(commentId) + .orElseThrow(() -> new NotFoundException(CommentExceptionType.COMMENT_NOT_FOUND)); + + comment.validateBelong(post); + comment.validateWriter(member); + + commentRepository.delete(comment); + } + } diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java index e9b53ea99..fc2822105 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java @@ -9,8 +9,10 @@ import com.votogether.domain.post.dto.request.CommentRegisterRequest; import com.votogether.domain.post.entity.Post; import com.votogether.domain.post.entity.PostBody; +import com.votogether.domain.post.entity.comment.Comment; import com.votogether.domain.post.repository.CommentRepository; import com.votogether.domain.post.repository.PostRepository; +import com.votogether.exception.BadRequestException; import com.votogether.exception.NotFoundException; import com.votogether.fixtures.MemberFixtures; import java.time.LocalDateTime; @@ -74,4 +76,128 @@ void createComment() { } + @Nested + @DisplayName("게시글 댓글 삭제") + class DeleteComment { + + @Test + @DisplayName("존재하지 않는 게시글이라면 예외를 던진다.") + void emptyPost() { + // given + Member member = memberRepository.save(MemberFixtures.MALE_20.get()); + + // when, then + assertThatThrownBy(() -> postCommentService.deleteComment(member, -1L, 1L)) + .isInstanceOf(NotFoundException.class) + .hasMessage("해당 게시글이 존재하지 않습니다."); + } + + @Test + @DisplayName("존재하지 않는 댓글이라면 예외를 던진다.") + void emptyComment() { + // given + Member member = memberRepository.save(MemberFixtures.MALE_20.get()); + Post post = postRepository.save( + Post.builder() + .member(member) + .postBody(PostBody.builder().title("title").content("content").build()) + .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) + .build() + ); + + // when, then + assertThatThrownBy(() -> postCommentService.deleteComment(member, post.getId(), -1L)) + .isInstanceOf(NotFoundException.class) + .hasMessage("해당 댓글이 존재하지 않습니다."); + } + + @Test + @DisplayName("댓글의 게시글과 일치하지 않으면 예외를 던진다.") + void invalidBelongPost() { + // given + Member member = memberRepository.save(MemberFixtures.MALE_20.get()); + Post postA = postRepository.save( + Post.builder() + .member(member) + .postBody(PostBody.builder().title("titleA").content("contentA").build()) + .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) + .build() + ); + Post postB = postRepository.save( + Post.builder() + .member(member) + .postBody(PostBody.builder().title("titleB").content("contentB").build()) + .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) + .build() + ); + Comment comment = commentRepository.save( + Comment.builder() + .member(member) + .post(postA) + .content("comment") + .build() + ); + + // when, then + assertThatThrownBy(() -> postCommentService.deleteComment(member, postB.getId(), comment.getId())) + .isInstanceOf(BadRequestException.class) + .hasMessage("댓글의 게시글 정보와 일치하지 않습니다."); + } + + @Test + @DisplayName("댓글의 작성자가 아니라면 예외르 던진다.") + void invalidWriter() { + // given + Member memberA = memberRepository.save(MemberFixtures.MALE_20.get()); + Member memberB = memberRepository.save(MemberFixtures.FEMALE_20.get()); + Post post = postRepository.save( + Post.builder() + .member(memberA) + .postBody(PostBody.builder().title("titleA").content("contentA").build()) + .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) + .build() + ); + Comment comment = commentRepository.save( + Comment.builder() + .member(memberB) + .post(post) + .content("comment") + .build() + ); + + // when, then + assertThatThrownBy(() -> postCommentService.deleteComment(memberA, post.getId(), comment.getId())) + .isInstanceOf(BadRequestException.class) + .hasMessage("댓글 작성자가 아닙니다."); + } + + @Test + @DisplayName("게시글의 댓글을 삭제한다.") + void deleteComment() { + // given + Member member = memberRepository.save(MemberFixtures.MALE_20.get()); + Post post = postRepository.save( + Post.builder() + .member(member) + .postBody(PostBody.builder().title("titleA").content("contentA").build()) + .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) + .build() + ); + Comment comment = commentRepository.save( + Comment.builder() + .member(member) + .post(post) + .content("comment") + .build() + ); + + // when + postCommentService.deleteComment(member, post.getId(), comment.getId()); + + // then + assertThat(commentRepository.findAll()).isEmpty(); + } + + } + } From 6b2b5f1fa66c31288b3737c15c77d967c8bb806e Mon Sep 17 00:00:00 2001 From: woo-chang Date: Fri, 28 Jul 2023 15:11:17 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20(#131)=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PostCommentController.java | 20 +++++ .../controller/PostCommentControllerTest.java | 76 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java index c591bc2ad..422b3508d 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java @@ -16,6 +16,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -49,4 +50,23 @@ public ResponseEntity createComment( return ResponseEntity.status(HttpStatus.CREATED).build(); } + @Operation(summary = "게시글 댓글 삭제", description = "게시글 댓글을 삭제한다.") + @ApiResponses({ + @ApiResponse(responseCode = "204", description = "게시글 댓글 삭제 성공"), + @ApiResponse( + responseCode = "404", + description = "[존재하지 않는 게시글, 존재하지 않는 댓글]", + content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) + ) + }) + @DeleteMapping("/{postId}/comments/{commentId}") + public ResponseEntity deleteComment( + @Auth final Member member, + @PathVariable @Parameter(description = "게시글 ID") final Long postId, + @PathVariable @Parameter(description = "댓글 ID") final Long commentId + ) { + postCommentService.deleteComment(member, postId, commentId); + return ResponseEntity.noContent().build(); + } + } diff --git a/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java b/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java index 887e3c85d..37e5d6232 100644 --- a/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java +++ b/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java @@ -2,10 +2,13 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willDoNothing; +import com.votogether.domain.member.entity.Member; import com.votogether.domain.member.service.MemberService; import com.votogether.domain.post.dto.request.CommentRegisterRequest; import com.votogether.domain.post.service.PostCommentService; @@ -40,7 +43,7 @@ class PostCommentControllerTest { TokenProcessor tokenProcessor; @BeforeEach - void setUp(final WebApplicationContext webApplicationContext) { + void setUp(WebApplicationContext webApplicationContext) { RestAssuredMockMvc.standaloneSetup(new PostCommentController(postCommentService)); RestAssuredMockMvc.webAppContextSetup(webApplicationContext); } @@ -72,12 +75,13 @@ void invalidIDType(String id) throws Exception { @ParameterizedTest @NullAndEmptySource @DisplayName("댓글 내용이 존재하지 않으면 400을 응답한다.") - void emptyContent(final String content) throws Exception { + void emptyContent(String content) throws Exception { // given TokenPayload tokenPayload = new TokenPayload(1L, 1L, 1L); given(tokenProcessor.resolveToken(anyString())).willReturn("token"); given(tokenProcessor.parseToken(anyString())).willReturn(tokenPayload); given(memberService.findById(anyLong())).willReturn(MemberFixtures.MALE_20.get()); + CommentRegisterRequest commentRegisterRequest = new CommentRegisterRequest(content); // when, then @@ -100,7 +104,10 @@ void createComment() throws Exception { given(tokenProcessor.resolveToken(anyString())).willReturn("token"); given(tokenProcessor.parseToken(anyString())).willReturn(tokenPayload); given(memberService.findById(anyLong())).willReturn(MemberFixtures.MALE_20.get()); + CommentRegisterRequest commentRegisterRequest = new CommentRegisterRequest("댓글입니다."); + willDoNothing().given(postCommentService) + .createComment(any(Member.class), anyLong(), any(CommentRegisterRequest.class)); // when, then RestAssuredMockMvc.given().log().all() @@ -114,4 +121,69 @@ void createComment() throws Exception { } + @Nested + @DisplayName("게시글 댓글 삭제") + class DeleteComment { + + @ParameterizedTest + @ValueSource(strings = {"@", "a", "가"}) + @DisplayName("게시글 ID가 Long 타입으로 변환할 수 없는 값이라면 400을 응답한다.") + void invalidPostIDType(String postId) throws Exception { + // given + TokenPayload tokenPayload = new TokenPayload(1L, 1L, 1L); + given(tokenProcessor.resolveToken(anyString())).willReturn("token"); + given(tokenProcessor.parseToken(anyString())).willReturn(tokenPayload); + given(memberService.findById(anyLong())).willReturn(MemberFixtures.MALE_20.get()); + + // when, then + RestAssuredMockMvc.given().log().all() + .headers(HttpHeaders.AUTHORIZATION, "Bearer token") + .when().delete("/posts/{postId}/comments/{commentId}", postId, 1L) + .then().log().all() + .status(HttpStatus.BAD_REQUEST) + .body("code", equalTo(-9998)) + .body("message", containsString("postId는 Long 타입이 필요합니다.")); + } + + @ParameterizedTest + @ValueSource(strings = {"@", "a", "가"}) + @DisplayName("댓글 ID가 Long 타입으로 변환할 수 없는 값이라면 400을 응답한다.") + void invalidCommentIDType(String commentId) throws Exception { + // given + TokenPayload tokenPayload = new TokenPayload(1L, 1L, 1L); + given(tokenProcessor.resolveToken(anyString())).willReturn("token"); + given(tokenProcessor.parseToken(anyString())).willReturn(tokenPayload); + given(memberService.findById(anyLong())).willReturn(MemberFixtures.MALE_20.get()); + + // when, then + RestAssuredMockMvc.given().log().all() + .headers(HttpHeaders.AUTHORIZATION, "Bearer token") + .when().delete("/posts/{postId}/comments/{commentId}", 1L, commentId) + .then().log().all() + .status(HttpStatus.BAD_REQUEST) + .body("code", equalTo(-9998)) + .body("message", containsString("commentId는 Long 타입이 필요합니다.")); + } + + @Test + @DisplayName("댓글을 정상적으로 삭제하면 204를 응답한다.") + void deleteComment() throws Exception { + // given + TokenPayload tokenPayload = new TokenPayload(1L, 1L, 1L); + given(tokenProcessor.resolveToken(anyString())).willReturn("token"); + given(tokenProcessor.parseToken(anyString())).willReturn(tokenPayload); + given(memberService.findById(anyLong())).willReturn(MemberFixtures.MALE_20.get()); + + willDoNothing().given(postCommentService).deleteComment(any(Member.class), anyLong(), anyLong()); + + // when, then + RestAssuredMockMvc.given().log().all() + .headers(HttpHeaders.AUTHORIZATION, "Bearer token") + .when().delete("/posts/{postId}/comments/{commentId}", 1L, 1L) + .then().log().all() + .status(HttpStatus.NO_CONTENT); + } + + } + } From 8f12c523dc7e1a8714e38a6d8db02e8c28406968 Mon Sep 17 00:00:00 2001 From: woo-chang Date: Fri, 28 Jul 2023 15:14:30 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20(#131)=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=AC=B8=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PostCommentController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java index 422b3508d..96448ff52 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java @@ -55,7 +55,7 @@ public ResponseEntity createComment( @ApiResponse(responseCode = "204", description = "게시글 댓글 삭제 성공"), @ApiResponse( responseCode = "404", - description = "[존재하지 않는 게시글, 존재하지 않는 댓글]", + description = "존재하지 않는 게시글, 존재하지 않는 댓글", content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) ) }) From b4032bb8268655eb0b74c277992e79808647f38b Mon Sep 17 00:00:00 2001 From: woo-chang Date: Sat, 29 Jul 2023 19:53:46 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20(#131)=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EB=90=9C=20=EB=A9=A4=EB=B2=84=20=EB=A7=A4=EA=B0=9C=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=9C=84=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PostCommentController.java | 6 +++--- .../domain/post/service/PostCommentService.java | 2 +- .../post/controller/PostCommentControllerTest.java | 2 +- .../domain/post/service/PostCommentServiceTest.java | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java index 96448ff52..e788a1d05 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostCommentController.java @@ -61,11 +61,11 @@ public ResponseEntity createComment( }) @DeleteMapping("/{postId}/comments/{commentId}") public ResponseEntity deleteComment( - @Auth final Member member, @PathVariable @Parameter(description = "게시글 ID") final Long postId, - @PathVariable @Parameter(description = "댓글 ID") final Long commentId + @PathVariable @Parameter(description = "댓글 ID") final Long commentId, + @Auth final Member member ) { - postCommentService.deleteComment(member, postId, commentId); + postCommentService.deleteComment(postId, commentId, member); return ResponseEntity.noContent().build(); } diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java index dc5edfade..a03dd0153 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java @@ -38,7 +38,7 @@ public void createComment( } @Transactional - public void deleteComment(final Member member, final Long postId, final Long commentId) { + public void deleteComment(final Long postId, final Long commentId, final Member member) { final Post post = postRepository.findById(postId) .orElseThrow(() -> new NotFoundException(PostExceptionType.POST_NOT_FOUND)); final Comment comment = commentRepository.findById(commentId) diff --git a/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java b/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java index 37e5d6232..9b75fa295 100644 --- a/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java +++ b/backend/src/test/java/com/votogether/domain/post/controller/PostCommentControllerTest.java @@ -174,7 +174,7 @@ void deleteComment() throws Exception { given(tokenProcessor.parseToken(anyString())).willReturn(tokenPayload); given(memberService.findById(anyLong())).willReturn(MemberFixtures.MALE_20.get()); - willDoNothing().given(postCommentService).deleteComment(any(Member.class), anyLong(), anyLong()); + willDoNothing().given(postCommentService).deleteComment(anyLong(), anyLong(), any(Member.class)); // when, then RestAssuredMockMvc.given().log().all() diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java index fc2822105..cd81b3687 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java @@ -87,7 +87,7 @@ void emptyPost() { Member member = memberRepository.save(MemberFixtures.MALE_20.get()); // when, then - assertThatThrownBy(() -> postCommentService.deleteComment(member, -1L, 1L)) + assertThatThrownBy(() -> postCommentService.deleteComment(-1L, 1L, member)) .isInstanceOf(NotFoundException.class) .hasMessage("해당 게시글이 존재하지 않습니다."); } @@ -106,7 +106,7 @@ void emptyComment() { ); // when, then - assertThatThrownBy(() -> postCommentService.deleteComment(member, post.getId(), -1L)) + assertThatThrownBy(() -> postCommentService.deleteComment(post.getId(), -1L, member)) .isInstanceOf(NotFoundException.class) .hasMessage("해당 댓글이 존재하지 않습니다."); } @@ -139,7 +139,7 @@ void invalidBelongPost() { ); // when, then - assertThatThrownBy(() -> postCommentService.deleteComment(member, postB.getId(), comment.getId())) + assertThatThrownBy(() -> postCommentService.deleteComment(postB.getId(), comment.getId(), member)) .isInstanceOf(BadRequestException.class) .hasMessage("댓글의 게시글 정보와 일치하지 않습니다."); } @@ -166,7 +166,7 @@ void invalidWriter() { ); // when, then - assertThatThrownBy(() -> postCommentService.deleteComment(memberA, post.getId(), comment.getId())) + assertThatThrownBy(() -> postCommentService.deleteComment(post.getId(), comment.getId(), memberA)) .isInstanceOf(BadRequestException.class) .hasMessage("댓글 작성자가 아닙니다."); } @@ -192,7 +192,7 @@ void deleteComment() { ); // when - postCommentService.deleteComment(member, post.getId(), comment.getId()); + postCommentService.deleteComment(post.getId(), comment.getId(), member); // then assertThat(commentRepository.findAll()).isEmpty(); From 541ff3d1c92ca3bac998dd90b5a5bc099adcd935 Mon Sep 17 00:00:00 2001 From: woo-chang Date: Sat, 29 Jul 2023 19:55:50 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20(#131)=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98=EC=A0=95=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EB=B9=8C=EB=8D=94=20=EC=B2=B4=EC=9D=B4?= =?UTF-8?q?=EB=8B=9D=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/entity/comment/CommentTest.java | 6 +++--- .../domain/post/service/PostCommentServiceTest.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java b/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java index d8e727edb..8ebbe2aa3 100644 --- a/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java +++ b/backend/src/test/java/com/votogether/domain/post/entity/comment/CommentTest.java @@ -51,7 +51,7 @@ void invalidWriter() { .content("content") .build(); Post post = Post.builder() - .member(member) + .writer(member) .postBody(body) .deadline(LocalDateTime.now()) .build(); @@ -79,7 +79,7 @@ void invalidPost() { .content("content") .build(); Post postA = Post.builder() - .member(member) + .writer(member) .postBody(bodyA) .deadline(LocalDateTime.now()) .build(); @@ -88,7 +88,7 @@ void invalidPost() { .content("content") .build(); Post postB = Post.builder() - .member(member) + .writer(member) .postBody(bodyB) .deadline(LocalDateTime.now()) .build(); diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java index 4cca1bdfd..f6580a61a 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostCommentServiceTest.java @@ -99,7 +99,7 @@ void emptyComment() { Member member = memberRepository.save(MemberFixtures.MALE_20.get()); Post post = postRepository.save( Post.builder() - .member(member) + .writer(member) .postBody(PostBody.builder().title("title").content("content").build()) .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) .build() @@ -118,14 +118,14 @@ void invalidBelongPost() { Member member = memberRepository.save(MemberFixtures.MALE_20.get()); Post postA = postRepository.save( Post.builder() - .member(member) + .writer(member) .postBody(PostBody.builder().title("titleA").content("contentA").build()) .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) .build() ); Post postB = postRepository.save( Post.builder() - .member(member) + .writer(member) .postBody(PostBody.builder().title("titleB").content("contentB").build()) .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) .build() @@ -152,7 +152,7 @@ void invalidWriter() { Member memberB = memberRepository.save(MemberFixtures.FEMALE_20.get()); Post post = postRepository.save( Post.builder() - .member(memberA) + .writer(memberA) .postBody(PostBody.builder().title("titleA").content("contentA").build()) .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) .build() @@ -178,7 +178,7 @@ void deleteComment() { Member member = memberRepository.save(MemberFixtures.MALE_20.get()); Post post = postRepository.save( Post.builder() - .member(member) + .writer(member) .postBody(PostBody.builder().title("titleA").content("contentA").build()) .deadline(LocalDateTime.of(2100, 7, 12, 0, 0)) .build() From 37e640a95e3c43e41eb4789c4cdd5379c79c7b29 Mon Sep 17 00:00:00 2001 From: woo-chang Date: Sat, 29 Jul 2023 19:58:16 +0900 Subject: [PATCH 7/7] =?UTF-8?q?chore:=20(#131)=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/votogether/domain/post/entity/PostTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java index a8ecda16b..4df44c37b 100644 --- a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java +++ b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java @@ -1,6 +1,5 @@ package com.votogether.domain.post.entity; -import static com.votogether.fixtures.MemberFixtures.FEMALE_20; import static com.votogether.fixtures.MemberFixtures.MALE_30; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll;