From ebdc9ba6243988193757ca74ac942ad5acb2e053 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 3 Nov 2022 20:28:31 +0900 Subject: [PATCH] =?UTF-8?q?#27=20feat:=20Comment=20=EC=88=98=EC=A0=95=20AP?= =?UTF-8?q?I=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); + } }