diff --git a/src/main/java/treehouse/server/api/comment/business/CommentService.java b/src/main/java/treehouse/server/api/comment/business/CommentService.java index 6de1641..06f8699 100644 --- a/src/main/java/treehouse/server/api/comment/business/CommentService.java +++ b/src/main/java/treehouse/server/api/comment/business/CommentService.java @@ -169,6 +169,9 @@ public CommentResponseDTO.CommentIdResponseDto createComment(User user, Long tre public CommentResponseDTO.CommentIdResponseDto createReply(User user, Long treehouseId, Long postId, Long parentId, CommentRequestDTO.createComment request){ + if(commentQueryAdapter.getCommentById(parentId).getParentId()!=-1L){ + throw new CommentException(GlobalErrorCode.REPLY_CREATE_BAD_REQUEST); + } TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId); Post post = postQueryAdapter.findById(postId); Member writer = memberQueryAdapter.findByUserAndTreehouse(user, treehouse); @@ -181,8 +184,13 @@ public CommentResponseDTO.CommentIdResponseDto createReply(User user, Long treeh public void deleteComment(User user, Long treehouseId, Long postId, Long commentId) { Comment comment = commentQueryAdapter.getCommentById(commentId); + Member loginMember = memberQueryAdapter.findByUserAndTreehouse(user, treehouseQueryAdapter.getTreehouseById(treehouseId)); + Member commentWriter = commentQueryAdapter.getCommentById(commentId).getWriter(); + Member postWriter = postQueryAdapter.findById(postId).getWriter(); - commentCommandAdapter.deleteComment(comment); + if (loginMember.getId() == commentWriter.getId() || loginMember.getId() == postWriter.getId()) { + commentCommandAdapter.deleteComment(comment); + } else throw new CommentException(GlobalErrorCode.COMMENT_DELETE_FORBIDDEN); } @Transactional diff --git a/src/main/java/treehouse/server/api/comment/presentation/CommentApi.java b/src/main/java/treehouse/server/api/comment/presentation/CommentApi.java index cdd2467..eee6b8e 100644 --- a/src/main/java/treehouse/server/api/comment/presentation/CommentApi.java +++ b/src/main/java/treehouse/server/api/comment/presentation/CommentApi.java @@ -83,7 +83,7 @@ public CommonResponse deleteComment( @AuthMember @Parameter(hidden = true) User user ) { - commentService.deleteComment(user,commentId,treehouseId,postId); + commentService.deleteComment(user,treehouseId,postId, commentId); return CommonResponse.onSuccess(null); } diff --git a/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java b/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java index 80fa6b7..bf5aeb0 100644 --- a/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java +++ b/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java @@ -65,11 +65,17 @@ public enum GlobalErrorCode implements BaseErrorCode{ // POST + 404 Not Found - 찾을 수 없음 POST_NOT_FOUND(NOT_FOUND, "POST404_1", "존재하지 않는 게시글입니다."), + // COMMENT + 403 Forbidden - 금지됨 + COMMENT_SELF_REPORT(FORBIDDEN, "COMMENT403_1", "자신의 댓글은 신고할 수 없습니다."), + + // COMMENT + 403 Forbidden + COMMENT_DELETE_FORBIDDEN(FORBIDDEN, "COMMENT403_2", "자신이 작성한 게시글에 대한 댓글이나 자신이 작성한 댓글만 삭제 가능합니다."), + // COMMENT + 404 Not Found - 찾을 수 없음 COMMENT_NOT_FOUND(NOT_FOUND, "COMMENT404_1", "존재하지 않는 댓글입니다."), - // COMMENT + 403 Forbidden - 금지됨 - COMMENT_SELF_REPORT(FORBIDDEN, "COMMENT403_1", "자신의 댓글은 신고할 수 없습니다."), + // REPLY + 400 Bad Request - 잘못된 요청 + REPLY_CREATE_BAD_REQUEST(BAD_REQUEST, "REPLY400_1", "댓글에 대해서만 대댓글 작성 가능합니다."), // REPLY + 404 Not Found - 찾을 수 없음 REPLY_NOT_FOUND(NOT_FOUND, "REPLY404_1", "존재하지 않는 답글입니다."),