From f68cbde6c5294257d18fc3e414aa98939dfa2def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AC=B8=EC=A4=80=ED=98=B8?= Date: Tue, 26 Mar 2024 16:39:51 +0900 Subject: [PATCH] noti cascade --- .../com/example/just/Repository/NotificationRepository.java | 2 ++ src/main/java/com/example/just/Service/CommentService.java | 1 + src/main/java/com/example/just/Service/PostService.java | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/src/main/java/com/example/just/Repository/NotificationRepository.java b/src/main/java/com/example/just/Repository/NotificationRepository.java index eca54e91..1b6b8b9c 100644 --- a/src/main/java/com/example/just/Repository/NotificationRepository.java +++ b/src/main/java/com/example/just/Repository/NotificationRepository.java @@ -16,5 +16,7 @@ public interface NotificationRepository extends JpaRepository List findAllByReceiver(Member member); + void deleteAllByNotObjectIdAndNotType(Long notObjectId,String notType); + } diff --git a/src/main/java/com/example/just/Service/CommentService.java b/src/main/java/com/example/just/Service/CommentService.java index 0cb7068e..4d3ae58a 100644 --- a/src/main/java/com/example/just/Service/CommentService.java +++ b/src/main/java/com/example/just/Service/CommentService.java @@ -182,6 +182,7 @@ public ResponseEntity deleteComment(Long postId, Long commentId, Long me postDocument.setCommentSize(postDocument.getCommentSize() - 1); postContentESRespository.save(postDocument); commentRepository.deleteById(commentId); + notificationRepository.deleteAllByNotObjectIdAndNotType(commentId,"comment"); return ResponseEntity.ok("ok"); } else { return ResponseEntity.status(403).body("권한이 없습니다."); diff --git a/src/main/java/com/example/just/Service/PostService.java b/src/main/java/com/example/just/Service/PostService.java index 9ed46d45..8147d4cb 100644 --- a/src/main/java/com/example/just/Service/PostService.java +++ b/src/main/java/com/example/just/Service/PostService.java @@ -21,6 +21,7 @@ import com.example.just.Repository.HashTagESRepository; import com.example.just.Repository.HashTagMapRepository; +import com.example.just.Repository.NotificationRepository; import com.example.just.Repository.PostLikeRepository; import com.example.just.Response.ResponseGetMemberPostDto; import com.example.just.Response.ResponsePutPostDto; @@ -71,6 +72,9 @@ public class PostService { @Autowired private HashTagESRepository hashTagESRepository; + + @Autowired + private NotificationRepository notificationRepository; @Autowired private BlameRepository blameRepository; @Autowired @@ -527,6 +531,7 @@ public void deletePost(Long post_id) throws NotFoundException { postContentESRespository.deleteById(post_id); deleteHashTag(post); postRepository.deleteById(post_id); + notificationRepository.deleteAllByNotObjectIdAndNotType(post_id,"post"); } } } \ No newline at end of file