Skip to content

Commit

Permalink
feat : delete comment with hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong0329 committed Nov 17, 2024
1 parent 9fb6c95 commit d38ed90
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Comment> 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();
}

Expand Down

0 comments on commit d38ed90

Please sign in to comment.