From 3324484480ca763c636daa3f4254846726717abc Mon Sep 17 00:00:00 2001 From: hyxklee Date: Mon, 26 Aug 2024 16:46:15 +0900 Subject: [PATCH] =?UTF-8?q?HOTIFX:=20=EC=82=AD=EC=A0=9C=EB=90=9C=20?= =?UTF-8?q?=EB=8C=80=EB=8C=93=EA=B8=80=20=EB=8B=A4=EC=8B=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=ED=95=A0=20=EC=88=98=20=EC=97=86=EA=B2=8C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/NoticeCommentUsecaseImpl.java | 3 +++ .../usecase/PostCommentUsecaseImpl.java | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java index c3808459..5fbd7ac9 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java @@ -10,6 +10,7 @@ import leets.weeth.domain.comment.domain.service.CommentSaveService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; +import leets.weeth.global.common.error.exception.custom.CommentNotFoundException; import leets.weeth.global.common.error.exception.custom.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -81,6 +82,8 @@ public void deleteNoticeComment(Long commentId, Long userId) throws UserNotMatch commentDeleteService.delete(parentComment.getId()); } } + } else if (comment.getIsDeleted()) { // 삭제된 대댓글인 경우 예외 + throw new CommentNotFoundException(); } else { comment.markAsDeleted(); commentSaveService.save(comment); diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java b/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java index 0ec2eec9..d580ea68 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java @@ -10,6 +10,7 @@ import leets.weeth.domain.comment.domain.service.CommentSaveService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; +import leets.weeth.global.common.error.exception.custom.CommentNotFoundException; import leets.weeth.global.common.error.exception.custom.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -38,14 +39,14 @@ public void savePostComment(CommentDTO.Save dto, Long postId, Long userId) { Post post = postFindService.find(postId); Comment parentComment = null; - if(!(dto.parentCommentId() == null)) { + if (!(dto.parentCommentId() == null)) { parentComment = commentFindService.find(dto.parentCommentId()); } Comment comment = commentMapper.fromCommentDto(dto, post, user, parentComment); commentSaveService.save(comment); // 부모 댓글이 없다면 새 댓글로 추가 - if(parentComment == null) { + if (parentComment == null) { post.addComment(comment); } else { // 부모 댓글이 있다면 자녀 댓글로 추가 @@ -80,17 +81,19 @@ public void deletePostComment(Long commentId, Long userId) throws UserNotMatchEx - child가 없는 댓글인 경우 -> 자식이 없기 떄문에 나만 삭제함 */ // 현재 삭제하고자 하는 댓글이 자식이 없는 경우 - if(comment.getChildren().isEmpty()){ + if (comment.getChildren().isEmpty()) { Comment parentComment = findParentComment(commentId); commentDeleteService.delete(commentId); - if(parentComment != null){ + if (parentComment != null) { parentComment.getChildren().remove(comment); - if(parentComment.getIsDeleted() && parentComment.getChildren().isEmpty()){ + if (parentComment.getIsDeleted() && parentComment.getChildren().isEmpty()) { post.getComments().remove(parentComment); commentDeleteService.delete(parentComment.getId()); } } - } else{ + } else if (comment.getIsDeleted()) { // 삭제된 대댓글인 경우 예외 + throw new CommentNotFoundException(); + } else { comment.markAsDeleted(); commentSaveService.save(comment); }