From d38ed905d2718e846c24e66718b57c6b41a75642 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Mon, 18 Nov 2024 03:59:45 +0900 Subject: [PATCH] feat : delete comment with hierarchy --- .../service/CommentCommendService.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java b/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java index 407e429..f49c9ed 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java @@ -20,6 +20,8 @@ import com.wable.www.WableServer.external.fcm.service.FcmService; import com.wable.www.WableServer.external.s3.service.S3Service; import java.io.IOException; +import java.util.List; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -163,11 +165,27 @@ public void postCommentVer2(Long memberId, Long contentId, MultipartFile comment public void deleteComment(Long memberId, Long commentId) { deleteValidate(memberId, commentId); - notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentLiked",commentId); - notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("comment",commentId); - notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", commentId); - Comment deleteComment = commentRepository.findCommentByIdOrThrow(commentId); + if(deleteComment.getParentCommentId().equals(-1L)) { + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentLiked", commentId); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("comment", commentId); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", commentId); + + List childComment = commentRepository.findChildComments(commentId); + + for (Comment comment : childComment) { + Long childCommentId = comment.getId(); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childCommentLiked", childCommentId); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childComment", childCommentId); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", childCommentId); + comment.softDelete(); + } + } else { + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childCommentLiked", commentId); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childComment", commentId); + notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", commentId); + } + deleteComment.softDelete(); }