diff --git a/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java b/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java index 6bdd31df..c69ab3ad 100644 --- a/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java +++ b/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java @@ -24,8 +24,8 @@ public class NotificationTxEventListener { @Transactional(propagation = Propagation.REQUIRES_NEW) @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void handleNotificationCreateEvent(final NotificationCreateEvent event) { - realTimeNotificationService.sendNotification(event.authorId(), "review-notification", event); - log.info("saved notification content: {}", event); + long unreadCount = notificationService.countUnreadNotifications(event.authorId()); + realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); saveNotification(event); } diff --git a/src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java b/src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java index ef03335e..b71fbcc2 100644 --- a/src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java +++ b/src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java @@ -23,7 +23,8 @@ public class PostApprovalNotificationTxListener { @Async("eventTaskExecutor") @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void handlePostApprovalAlarmEvent(final PostApprovalNotificationEvent event) { - realTimeNotificationService.sendNotification(event.authorId(), "notification-post-approval", event); + final long unreadCount = notificationService.countUnreadNotifications(event.authorId()); + realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); saveNotification(event); } diff --git a/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java b/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java index 2f6a4487..7872521b 100644 --- a/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java +++ b/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java @@ -23,7 +23,8 @@ public class CheckListNotificationTxListener { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) @Transactional(propagation = Propagation.REQUIRES_NEW) public void handleCheckListCreatedHistory(final CheckListApprovalNotificationEvent event) { - realTimeNotificationService.sendNotification(event.authorId(), "notification-checklist-approval", event); + final long unreadCount = notificationService.countUnreadNotifications(event.authorId()); + realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); saveNotification(event); } diff --git a/src/main/java/kr/mywork/interfaces/notification/controller/RealNotificationController.java b/src/main/java/kr/mywork/interfaces/notification/controller/RealNotificationController.java index c2b56655..bd7ee813 100644 --- a/src/main/java/kr/mywork/interfaces/notification/controller/RealNotificationController.java +++ b/src/main/java/kr/mywork/interfaces/notification/controller/RealNotificationController.java @@ -21,11 +21,12 @@ public class RealNotificationController { private final RealTimeNotificationService realTimeNotificationService; private final NotificationService notificationService; - @GetMapping( value = "/real-notifications/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + @GetMapping(value = "/real-notifications/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public ResponseEntity connectForRealTimeNotification(@LoginMember LoginMemberDetail loginMemberDetail) { final SseEmitter sseEmitter = realTimeNotificationService.addSseEmitter(loginMemberDetail.memberId()); - long count = notificationService.countUnreadNotifications(loginMemberDetail.memberId()); - realTimeNotificationService.sendNotification(loginMemberDetail.memberId(), "notification-unread-count", count); + long unreadCount = notificationService.countUnreadNotifications(loginMemberDetail.memberId()); + realTimeNotificationService.sendNotification(loginMemberDetail.memberId(), "notification-unread-count", + unreadCount); return ResponseEntity.ok(sseEmitter); }