From 65def77417fa313071f78de0c5c6a97404b2f3f0 Mon Sep 17 00:00:00 2001 From: cooper Date: Wed, 9 Jul 2025 18:48:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20SSE=20=EC=95=88=EC=9D=BD=EC=9D=80=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=20?= =?UTF-8?q?=EC=A0=84=EB=8B=AC=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?(#345)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/event/NotificationTxEventListener.java | 4 ++-- .../post/listener/PostApprovalNotificationTxListener.java | 3 ++- .../listener/CheckListNotificationTxListener.java | 3 ++- .../controller/RealNotificationController.java | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) 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); }