From 1bb8a5f7d756c549febf3fce11907dfc4201d76b Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 3 Nov 2022 17:50:20 +0900 Subject: [PATCH 1/5] =?UTF-8?q?#27=20feat:=20Comment=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20API=20=EA=B5=AC=ED=98=84,=20status=EB=A5=BC=20INACTIVE?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/CommenrController.java | 23 +++++++++ .../dto/request/comment/DeleteCommentReq.java | 15 ++++++ .../response/comment/DeleteCommentRes.java | 50 +++++++++++++++++++ .../yogit/server/board/entity/Comment.java | 5 ++ .../comment/CommentExceptionList.java | 3 +- .../comment/NotHostOfCommentException.java | 9 ++++ .../board/repository/CommentRepository.java | 4 ++ .../board/service/comment/CommentService.java | 4 ++ .../service/comment/CommentServiceImpl.java | 25 ++++++++++ 9 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/comment/DeleteCommentReq.java create mode 100644 server/src/main/java/com/yogit/server/board/dto/response/comment/DeleteCommentRes.java create mode 100644 server/src/main/java/com/yogit/server/board/exception/comment/NotHostOfCommentException.java diff --git a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java index 09fba83..51fee92 100644 --- a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java +++ b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java @@ -1,7 +1,9 @@ package com.yogit.server.board.controller; import com.yogit.server.board.dto.request.comment.CreateCommentReq; +import com.yogit.server.board.dto.request.comment.DeleteCommentReq; import com.yogit.server.board.dto.response.comment.CommentRes; +import com.yogit.server.board.dto.response.comment.DeleteCommentRes; import com.yogit.server.board.service.comment.CommentService; import com.yogit.server.global.dto.ApplicationResponse; import com.yogit.server.user.entity.Gender; @@ -57,4 +59,25 @@ public ApplicationResponse createComment(@RequestBody @Validated Cre public ApplicationResponse> findAllComments(@PathVariable("clipBoardId") Long clipBoardId, @PathVariable("userId") Long userId){ return commentService.findAllComments(clipBoardId, userId); } + + + /** + * 코멘트 삭제 + * @author 토마스 + */ + @ApiOperation(value = "코멘트 삭제", notes = "코멘트 아이디를 입력해 코멘트 삭제 요청.") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 클립보드입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "1"), + @ApiImplicitParam(name = "clipBoardId", required = true, dataTypeClass = Long.class, example = "1") + }) + @PatchMapping("/{commentId}") + public ApplicationResponse deleteComment(@PathVariable("commentId") Long commentId, @RequestBody @Validated DeleteCommentReq deleteCommentReq){ + return commentService.deleteComment(deleteCommentReq, commentId); + } } diff --git a/server/src/main/java/com/yogit/server/board/dto/request/comment/DeleteCommentReq.java b/server/src/main/java/com/yogit/server/board/dto/request/comment/DeleteCommentReq.java new file mode 100644 index 0000000..3a5cb5d --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/comment/DeleteCommentReq.java @@ -0,0 +1,15 @@ +package com.yogit.server.board.dto.request.comment; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class DeleteCommentReq { + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; +} diff --git a/server/src/main/java/com/yogit/server/board/dto/response/comment/DeleteCommentRes.java b/server/src/main/java/com/yogit/server/board/dto/response/comment/DeleteCommentRes.java new file mode 100644 index 0000000..2a49e46 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/response/comment/DeleteCommentRes.java @@ -0,0 +1,50 @@ +package com.yogit.server.board.dto.response.comment; + +import com.yogit.server.board.entity.Comment; +import com.yogit.server.config.domain.BaseStatus; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class DeleteCommentRes { + + @ApiModelProperty(example = "1") + @ApiParam(value = "코멘트 ID") + private Long commentId; + + @ApiModelProperty(example = "ACTIVE") + @ApiParam(value = "객체 상태") + private BaseStatus status; + + @ApiModelProperty(example = "2022-07-13 16:29:30") + @ApiParam(value = "생성 시각") + private String createdAt; + + @ApiModelProperty(example = "2022-07-13 16:29:30") + @ApiParam(value = "마지막 업데이트 시각") + private String updatedAt; + + /* + 연관관계 편의 메서드 + */ + public static DeleteCommentRes toDto(Comment comment){ + return DeleteCommentRes.builder() + .commentId(comment.getId()) + .status(comment.getStatus()) + .createdAt(comment.getCreatedAt()) + .updatedAt(comment.getUpdatedAt()) + .build(); + } + + @Builder + public DeleteCommentRes(Long commentId, BaseStatus status, String createdAt, String updatedAt) { + this.commentId = commentId; + this.status = status; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } +} diff --git a/server/src/main/java/com/yogit/server/board/entity/Comment.java b/server/src/main/java/com/yogit/server/board/entity/Comment.java index 5930884..9e315c1 100644 --- a/server/src/main/java/com/yogit/server/board/entity/Comment.java +++ b/server/src/main/java/com/yogit/server/board/entity/Comment.java @@ -2,6 +2,7 @@ import com.yogit.server.board.dto.request.comment.CreateCommentReq; import com.yogit.server.config.domain.BaseEntity; +import com.yogit.server.config.domain.BaseStatus; import com.yogit.server.user.entity.User; import lombok.AccessLevel; import lombok.Getter; @@ -37,4 +38,8 @@ public Comment(CreateCommentReq dto, User user, ClipBoard clipBoard) { this.user = user; this.clipBoard = clipBoard; } + + public void deleteComment(){ + this.setStatus(BaseStatus.INACTIVE); + } } diff --git a/server/src/main/java/com/yogit/server/board/exception/comment/CommentExceptionList.java b/server/src/main/java/com/yogit/server/board/exception/comment/CommentExceptionList.java index a1dc65a..3a96ef0 100644 --- a/server/src/main/java/com/yogit/server/board/exception/comment/CommentExceptionList.java +++ b/server/src/main/java/com/yogit/server/board/exception/comment/CommentExceptionList.java @@ -10,7 +10,8 @@ @RequiredArgsConstructor public enum CommentExceptionList { - NOT_FOUND_COMMENT("CM0001", NOT_FOUND, "존재하지 않는 Comment입니다."); + NOT_FOUND_COMMENT("CM0001", NOT_FOUND, "존재하지 않는 Comment입니다."), + NOT_HOST_OF_COMMENT("CM0002", HttpStatus.BAD_REQUEST, "요청한 유저가 코멘트의 호스트가 아닙니다."); private final String CODE; private final HttpStatus HTTPSTATUS; diff --git a/server/src/main/java/com/yogit/server/board/exception/comment/NotHostOfCommentException.java b/server/src/main/java/com/yogit/server/board/exception/comment/NotHostOfCommentException.java new file mode 100644 index 0000000..3a70299 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/exception/comment/NotHostOfCommentException.java @@ -0,0 +1,9 @@ +package com.yogit.server.board.exception.comment; + + +public class NotHostOfCommentException extends CommentException{ + public NotHostOfCommentException(){ + super(CommentExceptionList.NOT_FOUND_COMMENT.getCODE(), CommentExceptionList.NOT_FOUND_COMMENT.getHTTPSTATUS(), CommentExceptionList.NOT_FOUND_COMMENT.getMESSAGE()); + } + +} diff --git a/server/src/main/java/com/yogit/server/board/repository/CommentRepository.java b/server/src/main/java/com/yogit/server/board/repository/CommentRepository.java index 9ced032..06da19b 100644 --- a/server/src/main/java/com/yogit/server/board/repository/CommentRepository.java +++ b/server/src/main/java/com/yogit/server/board/repository/CommentRepository.java @@ -6,9 +6,13 @@ import org.springframework.data.repository.query.Param; import java.util.List; +import java.util.Optional; public interface CommentRepository extends JpaRepository { @Query("select cm from Comment cm where cm.clipBoard.id = :clipBoardId and cm.status = 'ACTIVE'") List findAllCommentsByClipBoardId(@Param("clipBoardId") Long clipBoardId); + + @Query("select cm from Comment cm where cm.id = :commentId and cm.status='ACTIVE'") + Optional findCommentById(@Param("commentId") Long commentId); } diff --git a/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java b/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java index e4a3cc2..fb9ba83 100644 --- a/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java +++ b/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java @@ -1,7 +1,9 @@ package com.yogit.server.board.service.comment; import com.yogit.server.board.dto.request.comment.CreateCommentReq; +import com.yogit.server.board.dto.request.comment.DeleteCommentReq; import com.yogit.server.board.dto.response.comment.CommentRes; +import com.yogit.server.board.dto.response.comment.DeleteCommentRes; import com.yogit.server.global.dto.ApplicationResponse; import java.util.List; @@ -11,4 +13,6 @@ public interface CommentService { ApplicationResponse createComment(CreateCommentReq createCommentReq); ApplicationResponse> findAllComments(Long clipBoardId, Long userId); + + ApplicationResponse deleteComment(DeleteCommentReq deleteCommentReq, Long commentId); } diff --git a/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java index f0feafa..0520287 100644 --- a/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java @@ -1,10 +1,14 @@ package com.yogit.server.board.service.comment; import com.yogit.server.board.dto.request.comment.CreateCommentReq; +import com.yogit.server.board.dto.request.comment.DeleteCommentReq; +import com.yogit.server.board.dto.response.comment.DeleteCommentRes; import com.yogit.server.board.dto.response.comment.CommentRes; import com.yogit.server.board.entity.ClipBoard; import com.yogit.server.board.entity.Comment; import com.yogit.server.board.exception.clipboard.NotFoundClipBoardException; +import com.yogit.server.board.exception.comment.NotFoundCommentException; +import com.yogit.server.board.exception.comment.NotHostOfCommentException; import com.yogit.server.board.repository.ClipBoardRepository; import com.yogit.server.board.repository.CommentRepository; import com.yogit.server.global.dto.ApplicationResponse; @@ -61,4 +65,25 @@ public ApplicationResponse> findAllComments(Long clipBoardId, L return ApplicationResponse.ok(commentResList); } + + + @Transactional(readOnly = false) + @Override + public ApplicationResponse deleteComment(DeleteCommentReq dto, Long commentId){ + + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + Comment comment = commentRepository.findCommentById(commentId) + .orElseThrow(() -> new NotFoundCommentException()); + + //검증: 요청 유저가 코멘트를 생성한 사람인지 + if(!user.getId().equals(comment.getUser().getId())){ + throw new NotHostOfCommentException(); + } + + comment.deleteComment(); + DeleteCommentRes deleteCommentRes = DeleteCommentRes.toDto(comment); + return ApplicationResponse.ok(deleteCommentRes); + } } From c6fc1e804747247ae026d8c35a580401f960c887 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 3 Nov 2022 17:55:34 +0900 Subject: [PATCH 2/5] =?UTF-8?q?#27=20feat:=20CommentRes=EC=97=90=20status,?= =?UTF-8?q?=20createdAt,=20updatedAt=20=ED=95=84=EB=93=9C=EA=B0=92=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/comment/CommentRes.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/yogit/server/board/dto/response/comment/CommentRes.java b/server/src/main/java/com/yogit/server/board/dto/response/comment/CommentRes.java index cb75e1e..5b6ff9c 100644 --- a/server/src/main/java/com/yogit/server/board/dto/response/comment/CommentRes.java +++ b/server/src/main/java/com/yogit/server/board/dto/response/comment/CommentRes.java @@ -2,6 +2,7 @@ import com.yogit.server.board.entity.ClipBoard; import com.yogit.server.board.entity.Comment; +import com.yogit.server.config.domain.BaseStatus; import com.yogit.server.user.entity.User; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiParam; @@ -37,6 +38,18 @@ public class CommentRes { @ApiParam(value = "ClipBoard ID") private Long clipBoardId; + @ApiModelProperty(example = "ACTIVE") + @ApiParam(value = "객체 상태") + private BaseStatus status; + + @ApiModelProperty(example = "2022-07-13 16:29:30") + @ApiParam(value = "생성 시각") + private String createdAt; + + @ApiModelProperty(example = "2022-07-13 16:29:30") + @ApiParam(value = "마지막 업데이트 시각") + private String updatedAt; + public static CommentRes toDto(Comment comment){ return CommentRes.builder() .commentId(comment.getId()) @@ -45,16 +58,22 @@ public static CommentRes toDto(Comment comment){ .userName(comment.getUser().getName()) .profileImg(comment.getUser().getProfileImg()) .clipBoardId(comment.getClipBoard().getId()) + .status(comment.getStatus()) + .createdAt(comment.getCreatedAt()) + .updatedAt(comment.getUpdatedAt()) .build(); } @Builder - public CommentRes(Long commentId, String content, Long userId, String userName, String profileImg, Long clipBoardId) { + public CommentRes(Long commentId, String content, Long userId, String userName, String profileImg, Long clipBoardId, BaseStatus status, String createdAt, String updatedAt) { this.commentId = commentId; this.content = content; this.userId = userId; this.userName = userName; this.profileImg = profileImg; this.clipBoardId = clipBoardId; + this.status = status; + this.createdAt = createdAt; + this.updatedAt = updatedAt; } } From 17ded3fd44f4e324b97074166e3942fe10af9475 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 3 Nov 2022 18:02:40 +0900 Subject: [PATCH 3/5] =?UTF-8?q?#27=20fix:=20deleteComment=20=EC=9D=98=20@A?= =?UTF-8?q?piImplicitParam=20commentId=EC=98=88=EC=A0=9C=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 --- .../com/yogit/server/board/controller/CommenrController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java index 51fee92..bf52a7f 100644 --- a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java +++ b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java @@ -74,7 +74,7 @@ public ApplicationResponse> findAllComments(@PathVariable("clip }) @ApiImplicitParams({ @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "1"), - @ApiImplicitParam(name = "clipBoardId", required = true, dataTypeClass = Long.class, example = "1") + @ApiImplicitParam(name = "commentId", required = true, dataTypeClass = Long.class, example = "1") }) @PatchMapping("/{commentId}") public ApplicationResponse deleteComment(@PathVariable("commentId") Long commentId, @RequestBody @Validated DeleteCommentReq deleteCommentReq){ From e89e93b94c78548a736be29095dd725bade168b3 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 3 Nov 2022 18:09:16 +0900 Subject: [PATCH 4/5] =?UTF-8?q?#27=20feat:=20deleteComment=EC=97=90=20@Api?= =?UTF-8?q?Response=EB=A1=9C=20=EC=BD=94=EB=A9=98=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=97=90=EB=9F=AC=20=EC=98=88=EC=A0=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yogit/server/board/controller/CommenrController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java index bf52a7f..a7b4559 100644 --- a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java +++ b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java @@ -70,6 +70,7 @@ public ApplicationResponse> findAllComments(@PathVariable("clip @ApiResponse(code= 201, message = "요청에 성공하였습니다."), @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), @ApiResponse(code= 404, message = "존재하지 않는 클립보드입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 코멘트입니다."), @ApiResponse(code = 4000 , message = "서버 오류입니다.") }) @ApiImplicitParams({ From ebdc9ba6243988193757ca74ac942ad5acb2e053 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 3 Nov 2022 20:28:31 +0900 Subject: [PATCH 5/5] =?UTF-8?q?#27=20feat:=20Comment=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20API=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/CommenrController.java | 23 ++++++++++++++++ .../dto/request/comment/PatchCommentReq.java | 26 +++++++++++++++++++ .../yogit/server/board/entity/Comment.java | 5 ++++ .../board/service/comment/CommentService.java | 3 +++ .../service/comment/CommentServiceImpl.java | 22 ++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/comment/PatchCommentReq.java diff --git a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java index a7b4559..456db49 100644 --- a/server/src/main/java/com/yogit/server/board/controller/CommenrController.java +++ b/server/src/main/java/com/yogit/server/board/controller/CommenrController.java @@ -2,6 +2,7 @@ import com.yogit.server.board.dto.request.comment.CreateCommentReq; import com.yogit.server.board.dto.request.comment.DeleteCommentReq; +import com.yogit.server.board.dto.request.comment.PatchCommentReq; import com.yogit.server.board.dto.response.comment.CommentRes; import com.yogit.server.board.dto.response.comment.DeleteCommentRes; import com.yogit.server.board.service.comment.CommentService; @@ -81,4 +82,26 @@ public ApplicationResponse> findAllComments(@PathVariable("clip public ApplicationResponse deleteComment(@PathVariable("commentId") Long commentId, @RequestBody @Validated DeleteCommentReq deleteCommentReq){ return commentService.deleteComment(deleteCommentReq, commentId); } + + + /** + * 코멘트 수정 + * @author 토마스 + */ + @ApiOperation(value = "코멘트 수정", notes = "코멘트 아이디, 수정할 내용을 입력해 코멘트 수정 요청.") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 클립보드입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 코멘트입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "1"), + @ApiImplicitParam(name = "commentId", required = true, dataTypeClass = Long.class, example = "1") + }) + @PatchMapping("/{commentId}/content") + public ApplicationResponse updateComment(@PathVariable("commentId") Long commentId, @RequestBody @Validated PatchCommentReq patchCommentReq){ + return commentService.updateComment(patchCommentReq, commentId); + } } diff --git a/server/src/main/java/com/yogit/server/board/dto/request/comment/PatchCommentReq.java b/server/src/main/java/com/yogit/server/board/dto/request/comment/PatchCommentReq.java new file mode 100644 index 0000000..b6ad979 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/comment/PatchCommentReq.java @@ -0,0 +1,26 @@ +package com.yogit.server.board.dto.request.comment; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Data +@NoArgsConstructor +public class PatchCommentReq { + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "코멘트 ID", required = true) + private Long commentId; + + @ApiModelProperty(example = "경복궁역 몇 번 출구인가요?") + @ApiParam(value = "클립보드 상세 내용", required = true) + @NotBlank + private String content; +} diff --git a/server/src/main/java/com/yogit/server/board/entity/Comment.java b/server/src/main/java/com/yogit/server/board/entity/Comment.java index 9e315c1..1a59e51 100644 --- a/server/src/main/java/com/yogit/server/board/entity/Comment.java +++ b/server/src/main/java/com/yogit/server/board/entity/Comment.java @@ -1,6 +1,7 @@ package com.yogit.server.board.entity; import com.yogit.server.board.dto.request.comment.CreateCommentReq; +import com.yogit.server.board.dto.request.comment.PatchCommentReq; import com.yogit.server.config.domain.BaseEntity; import com.yogit.server.config.domain.BaseStatus; import com.yogit.server.user.entity.User; @@ -42,4 +43,8 @@ public Comment(CreateCommentReq dto, User user, ClipBoard clipBoard) { public void deleteComment(){ this.setStatus(BaseStatus.INACTIVE); } + + public void updateComment(PatchCommentReq dto){ + this.content = dto.getContent(); + } } diff --git a/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java b/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java index fb9ba83..68e3e2f 100644 --- a/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java +++ b/server/src/main/java/com/yogit/server/board/service/comment/CommentService.java @@ -2,6 +2,7 @@ import com.yogit.server.board.dto.request.comment.CreateCommentReq; import com.yogit.server.board.dto.request.comment.DeleteCommentReq; +import com.yogit.server.board.dto.request.comment.PatchCommentReq; import com.yogit.server.board.dto.response.comment.CommentRes; import com.yogit.server.board.dto.response.comment.DeleteCommentRes; import com.yogit.server.global.dto.ApplicationResponse; @@ -15,4 +16,6 @@ public interface CommentService { ApplicationResponse> findAllComments(Long clipBoardId, Long userId); ApplicationResponse deleteComment(DeleteCommentReq deleteCommentReq, Long commentId); + + ApplicationResponse updateComment(PatchCommentReq patchCommentReq, Long commentId); } diff --git a/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java index 0520287..e3932db 100644 --- a/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.java @@ -2,6 +2,7 @@ import com.yogit.server.board.dto.request.comment.CreateCommentReq; import com.yogit.server.board.dto.request.comment.DeleteCommentReq; +import com.yogit.server.board.dto.request.comment.PatchCommentReq; import com.yogit.server.board.dto.response.comment.DeleteCommentRes; import com.yogit.server.board.dto.response.comment.CommentRes; import com.yogit.server.board.entity.ClipBoard; @@ -86,4 +87,25 @@ public ApplicationResponse deleteComment(DeleteCommentReq dto, DeleteCommentRes deleteCommentRes = DeleteCommentRes.toDto(comment); return ApplicationResponse.ok(deleteCommentRes); } + + + @Transactional(readOnly = false) + @Override + public ApplicationResponse updateComment(PatchCommentReq dto, Long commentId){ + + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + Comment comment = commentRepository.findCommentById(dto.getCommentId()) + .orElseThrow(() -> new NotFoundCommentException()); + + //검증: 요청 유저가 코멘트를 생성한 사람인지 + if(!user.getId().equals(comment.getUser().getId())){ + throw new NotHostOfCommentException(); + } + + comment.updateComment(dto); + CommentRes commentRes = CommentRes.toDto(comment); + return ApplicationResponse.ok(commentRes); + } }