diff --git a/src/main/java/co/kr/jurumarble/notification/domain/Notification.java b/src/main/java/co/kr/jurumarble/notification/domain/Notification.java index 1c73f76..13282be 100644 --- a/src/main/java/co/kr/jurumarble/notification/domain/Notification.java +++ b/src/main/java/co/kr/jurumarble/notification/domain/Notification.java @@ -32,9 +32,8 @@ public class Notification extends BaseTimeEntity { @Column(nullable = false, name = "notification_type") private NotificationType notificationType; - @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_Id") - @OnDelete(action = OnDeleteAction.CASCADE) private User receiver; @Builder diff --git a/src/main/java/co/kr/jurumarble/notification/repository/NotificationRepository.java b/src/main/java/co/kr/jurumarble/notification/repository/NotificationRepository.java index 39441c8..ad6a82d 100644 --- a/src/main/java/co/kr/jurumarble/notification/repository/NotificationRepository.java +++ b/src/main/java/co/kr/jurumarble/notification/repository/NotificationRepository.java @@ -11,4 +11,7 @@ public interface NotificationRepository extends JpaRepository { @Query("SELECT n FROM Notification n WHERE n.receiver = :user ORDER BY n.createdDate DESC") List findNotificationsByUser(@Param("user") User user); + + @Query("SELECT n FROM Notification n WHERE n.url = :url") + List findNotificationsByUrl(@Param("url") String url); } diff --git a/src/main/java/co/kr/jurumarble/vote/domain/VoteDeleter.java b/src/main/java/co/kr/jurumarble/vote/domain/VoteDeleter.java index 4414546..8b7f09c 100644 --- a/src/main/java/co/kr/jurumarble/vote/domain/VoteDeleter.java +++ b/src/main/java/co/kr/jurumarble/vote/domain/VoteDeleter.java @@ -6,6 +6,8 @@ import co.kr.jurumarble.comment.repository.CommentRepository; import co.kr.jurumarble.exception.vote.VoteContentNotFoundException; import co.kr.jurumarble.exception.vote.VoteDrinkContentNotFoundException; +import co.kr.jurumarble.notification.domain.Notification; +import co.kr.jurumarble.notification.repository.NotificationRepository; import co.kr.jurumarble.vote.enums.VoteType; import co.kr.jurumarble.vote.repository.VoteContentRepository; import co.kr.jurumarble.vote.repository.VoteDrinkContentRepository; @@ -24,11 +26,13 @@ public class VoteDeleter { private final CommentRepository commentRepository; private final VoteResultRepository voteResultRepository; private final BookmarkRepository bookmarkRepository; + private final NotificationRepository notificationRepository; public void deleteVoteRelatedData(Vote vote) { deleteVoteContent(vote); deleteVoteComment(vote); deleteVoteResult(vote); deleteVoteBookmark(vote); + deleteVoteNotification(vote); } private void deleteVoteContent(Vote vote) { @@ -58,4 +62,8 @@ private void deleteVoteBookmark(Vote vote) { bookmarkRepository.deleteAll(bookmarks); } + private void deleteVoteNotification(Vote vote) { + List notifications = notificationRepository.findNotificationsByUrl(vote.getId().toString()); + notificationRepository.deleteAll(notifications); + } }