Skip to content

Commit

Permalink
Merge pull request #118 from jurumarble/fix/notification
Browse files Browse the repository at this point in the history
feat : 투표를 지우면 알람도 같이 삭제되도록 구현
  • Loading branch information
alsduq1117 authored Oct 22, 2023
2 parents 8f55208 + 7ed631e commit e9b8f34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
public interface NotificationRepository extends JpaRepository<Notification, Long> {
@Query("SELECT n FROM Notification n WHERE n.receiver = :user ORDER BY n.createdDate DESC")
List<Notification> findNotificationsByUser(@Param("user") User user);

@Query("SELECT n FROM Notification n WHERE n.url = :url")
List<Notification> findNotificationsByUrl(@Param("url") String url);
}
8 changes: 8 additions & 0 deletions src/main/java/co/kr/jurumarble/vote/domain/VoteDeleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -58,4 +62,8 @@ private void deleteVoteBookmark(Vote vote) {
bookmarkRepository.deleteAll(bookmarks);
}

private void deleteVoteNotification(Vote vote) {
List<Notification> notifications = notificationRepository.findNotificationsByUrl(vote.getId().toString());
notificationRepository.deleteAll(notifications);
}
}

0 comments on commit e9b8f34

Please sign in to comment.