diff --git a/src/main/java/kr/co/conceptbe/notification/app/NotificationService.java b/src/main/java/kr/co/conceptbe/notification/app/NotificationService.java index 49e2212..bea34df 100644 --- a/src/main/java/kr/co/conceptbe/notification/app/NotificationService.java +++ b/src/main/java/kr/co/conceptbe/notification/app/NotificationService.java @@ -4,6 +4,7 @@ import kr.co.conceptbe.auth.presentation.dto.AuthCredentials; import kr.co.conceptbe.idea.domain.Idea; import kr.co.conceptbe.idea.domain.event.CreatedIdeaEvent; +import kr.co.conceptbe.idea.domain.persistence.IdeaRepository; import kr.co.conceptbe.notification_setting.domain.IdeaNotificationSetting; import kr.co.conceptbe.notification_setting.domain.repository.NotificationSettingRepository; import kr.co.conceptbe.member.exception.NotFoundAuthCredentialException; @@ -26,6 +27,7 @@ public class NotificationService { private final NotificationRepository notificationRepository; private final NotificationSettingRepository notificationSettingRepository; private final NotificationTrigger notificationTrigger; + private final IdeaRepository ideaRepository; @Transactional(readOnly = true) public List findAllNotifications( @@ -60,7 +62,7 @@ public void readNotification(AuthCredentials auth, Long notificationId) { .orElseThrow( () -> new IllegalArgumentException("Not Found Notification ID : " + notificationId) ); - notification.read(memberId); + notification.read(memberId, ideaRepository::findById); notificationRepository.save(notification); } diff --git a/src/main/java/kr/co/conceptbe/notification/app/dto/NotificationResponse.java b/src/main/java/kr/co/conceptbe/notification/app/dto/NotificationResponse.java index 2ed237c..32ff97d 100644 --- a/src/main/java/kr/co/conceptbe/notification/app/dto/NotificationResponse.java +++ b/src/main/java/kr/co/conceptbe/notification/app/dto/NotificationResponse.java @@ -9,7 +9,8 @@ public record NotificationResponse( Long feedId, String title, String createAt, - List badges + List badges, + boolean isAlreadyRead ) { public static NotificationResponse from(IdeaNotification notification) { @@ -22,7 +23,8 @@ public static NotificationResponse from(IdeaNotification notification) { notification.getIdeaId(), notification.getTitle(), notification.getCreatedAt().toString(), - ideaBranches + ideaBranches, + notification.isAlreadyRead() ); } diff --git a/src/main/java/kr/co/conceptbe/notification/domain/IdeaNotification.java b/src/main/java/kr/co/conceptbe/notification/domain/IdeaNotification.java index c917cbe..aeedbc5 100644 --- a/src/main/java/kr/co/conceptbe/notification/domain/IdeaNotification.java +++ b/src/main/java/kr/co/conceptbe/notification/domain/IdeaNotification.java @@ -1,6 +1,7 @@ package kr.co.conceptbe.notification.domain; import jakarta.persistence.*; +import java.util.Optional; import kr.co.conceptbe.common.entity.base.BaseTimeEntity; import kr.co.conceptbe.idea.domain.Idea; import kr.co.conceptbe.idea.domain.IdeaBranch; @@ -104,10 +105,16 @@ private List splitBadges(String badges) { return new ArrayList<>(List.of(badgesEach)); } - public void read(Long memberId) { + public void read(Long memberId, Function> getIdea) { if (!memberId.equals(this.memberId)) { throw new IllegalArgumentException("다른 계정의 알림을 읽을 수 없습니다."); } + + Optional idea = getIdea.apply(this.ideaId); + if (idea.isEmpty()) { + throw new IllegalArgumentException("게시글을 찾을 수 없습니다."); + } + isAlreadyRead = true; }