Skip to content

Commit d38ed90

Browse files
committed
feat : delete comment with hierarchy
1 parent 9fb6c95 commit d38ed90

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.wable.www.WableServer.external.fcm.service.FcmService;
2121
import com.wable.www.WableServer.external.s3.service.S3Service;
2222
import java.io.IOException;
23+
import java.util.List;
24+
2325
import lombok.RequiredArgsConstructor;
2426
import org.springframework.stereotype.Service;
2527
import org.springframework.transaction.annotation.Transactional;
@@ -163,11 +165,27 @@ public void postCommentVer2(Long memberId, Long contentId, MultipartFile comment
163165
public void deleteComment(Long memberId, Long commentId) {
164166
deleteValidate(memberId, commentId);
165167

166-
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentLiked",commentId);
167-
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("comment",commentId);
168-
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", commentId);
169-
170168
Comment deleteComment = commentRepository.findCommentByIdOrThrow(commentId);
169+
if(deleteComment.getParentCommentId().equals(-1L)) {
170+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentLiked", commentId);
171+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("comment", commentId);
172+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", commentId);
173+
174+
List<Comment> childComment = commentRepository.findChildComments(commentId);
175+
176+
for (Comment comment : childComment) {
177+
Long childCommentId = comment.getId();
178+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childCommentLiked", childCommentId);
179+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childComment", childCommentId);
180+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", childCommentId);
181+
comment.softDelete();
182+
}
183+
} else {
184+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childCommentLiked", commentId);
185+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("childComment", commentId);
186+
notificationRepository.deleteByNotificationTriggerTypeAndNotificationTriggerId("commentGhost", commentId);
187+
}
188+
171189
deleteComment.softDelete();
172190
}
173191

0 commit comments

Comments
 (0)