diff --git a/src/main/java/com/chooz/notification/application/service/NotificationQueryService.java b/src/main/java/com/chooz/notification/application/service/NotificationQueryService.java index e68243f..c4acfa5 100644 --- a/src/main/java/com/chooz/notification/application/service/NotificationQueryService.java +++ b/src/main/java/com/chooz/notification/application/service/NotificationQueryService.java @@ -56,7 +56,7 @@ public List findVoteUsersByPostId(Long postId) { return notificationQueryRepository.findVoteUsersByPostId(postId); } public NotificationPresentResponse present(Long userId) { - return NotificationPresentResponse.of(notificationRepository.existsByReceiverIdAndIsReadFalseAndDeletedFalse(userId)); + return NotificationPresentResponse.of(notificationRepository.existsByReceiverIdAndIsReadFalseAndDeletedFalseAndIsValidTrue(userId)); } public List findByTargetIdAndType(Long id, TargetType targetType) { return notificationRepository.findByTargetIdAndType(id, targetType); diff --git a/src/main/java/com/chooz/notification/domain/NotificationRepository.java b/src/main/java/com/chooz/notification/domain/NotificationRepository.java index c99413c..440eb9c 100644 --- a/src/main/java/com/chooz/notification/domain/NotificationRepository.java +++ b/src/main/java/com/chooz/notification/domain/NotificationRepository.java @@ -7,7 +7,7 @@ public interface NotificationRepository { Notification save(Notification notification); void saveAll(List notifications); Optional findNotificationById(Long id); - boolean existsByReceiverIdAndIsReadFalseAndDeletedFalse(Long userId); + boolean existsByReceiverIdAndIsReadFalseAndDeletedFalseAndIsValidTrue(Long userId); List findByTargetIdAndType(Long targetId, TargetType targetType); void deleteAllByUserId(Long userId); diff --git a/src/main/java/com/chooz/notification/persistence/NotificationJpaRepository.java b/src/main/java/com/chooz/notification/persistence/NotificationJpaRepository.java index c6d0ee7..bfe1cb9 100644 --- a/src/main/java/com/chooz/notification/persistence/NotificationJpaRepository.java +++ b/src/main/java/com/chooz/notification/persistence/NotificationJpaRepository.java @@ -11,7 +11,7 @@ @Repository public interface NotificationJpaRepository extends JpaRepository { - boolean existsByReceiverIdAndIsReadFalseAndDeletedFalse(Long userId); + boolean existsByReceiverIdAndIsReadFalseAndDeletedFalseAndIsValidTrue(Long userId); @Query(""" SELECT distinct n FROM Notification n diff --git a/src/main/java/com/chooz/notification/persistence/NotificationRepositoryImpl.java b/src/main/java/com/chooz/notification/persistence/NotificationRepositoryImpl.java index 906ba74..830c1c1 100644 --- a/src/main/java/com/chooz/notification/persistence/NotificationRepositoryImpl.java +++ b/src/main/java/com/chooz/notification/persistence/NotificationRepositoryImpl.java @@ -32,8 +32,8 @@ public Optional findNotificationById(Long id) { } @Override - public boolean existsByReceiverIdAndIsReadFalseAndDeletedFalse(Long userId) { - return notificationJpaRepository.existsByReceiverIdAndIsReadFalseAndDeletedFalse(userId); + public boolean existsByReceiverIdAndIsReadFalseAndDeletedFalseAndIsValidTrue(Long userId) { + return notificationJpaRepository.existsByReceiverIdAndIsReadFalseAndDeletedFalseAndIsValidTrue(userId); } @Override diff --git a/src/test/java/com/chooz/notification/application/NotificationInvalidListenerTest.java b/src/test/java/com/chooz/notification/application/NotificationInvalidListenerTest.java index ac8627e..dc89d2a 100644 --- a/src/test/java/com/chooz/notification/application/NotificationInvalidListenerTest.java +++ b/src/test/java/com/chooz/notification/application/NotificationInvalidListenerTest.java @@ -6,6 +6,7 @@ import com.chooz.commentLike.application.CommentLikeService; import com.chooz.notification.application.web.dto.NotificationDto; import com.chooz.notification.domain.NotificationQueryRepository; +import com.chooz.notification.presentation.dto.NotificationPresentResponse; import com.chooz.post.application.PostCommandService; import com.chooz.post.domain.PollChoiceRepository; import com.chooz.post.domain.Post; @@ -60,6 +61,9 @@ class NotificationInvalidListenerTest extends IntegrationTest { @Autowired PostCommandService postCommandService; + @Autowired + NotificationService notificationQueryService; + @AfterEach void tearDown() { voteRepository.deleteAllInBatch(); @@ -99,8 +103,11 @@ void InvalidNotificationByDeleteComment() throws Exception { null, PageRequest.ofSize(10) ).getContent(); + NotificationPresentResponse notificationPresentResponse = notificationQueryService.present(receiver.getId()); assertAll( - () -> assertThat(notifications.size()).isZero() + () -> assertThat(notifications.size()).isZero(), + () -> assertThat(notificationPresentResponse.present()).isFalse() + ); } @Test @@ -128,9 +135,11 @@ void InvalidNotificationByDeletePost() throws Exception { null, PageRequest.ofSize(10) ).getContent(); + NotificationPresentResponse notificationPresentResponse = notificationQueryService.present(user.getId()); assertAll( - () -> assertThat(notifications.size()).isZero() + () -> assertThat(notifications.size()).isZero(), + () -> assertThat(notificationPresentResponse.present()).isFalse() ); } }