From afa63ae090783642ac9674b8288484d0d2b758a6 Mon Sep 17 00:00:00 2001 From: seohyun-lee Date: Fri, 16 Aug 2024 20:17:58 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EA=B5=AC?= =?UTF-8?q?=EB=8F=85=EC=9D=84=20=EC=9C=84=ED=95=B4=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=EC=97=90=EC=84=9C=20=ED=97=A4?= =?UTF-8?q?=EB=8D=94=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/alarm/controller/AlarmController.java | 6 +++--- .../songpin/domain/alarm/service/EmitterService.java | 10 +++++----- .../java/sws/songpin/global/config/SecurityConfig.java | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/sws/songpin/domain/alarm/controller/AlarmController.java b/src/main/java/sws/songpin/domain/alarm/controller/AlarmController.java index 72c505e..85146af 100644 --- a/src/main/java/sws/songpin/domain/alarm/controller/AlarmController.java +++ b/src/main/java/sws/songpin/domain/alarm/controller/AlarmController.java @@ -19,9 +19,9 @@ public class AlarmController { private final AlarmService alarmService; @Operation(summary = "알림 구독", description = "알림을 구독합니다.") - @GetMapping(value = "/subscribe/{memberId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) // Content-Type 지정 - public ResponseEntity subscribe(@PathVariable("memberId") final Long memberId) { - return ResponseEntity.ok(emitterService.subscribe(memberId)); + @GetMapping(value = "/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE) // Content-Type 지정 + public ResponseEntity subscribe() { + return ResponseEntity.ok(emitterService.subscribe()); } @Operation(summary = "알림 목록 조회 및 읽음 처리", description = "알림 목록을 조회하고 읽음 처리합니다.") diff --git a/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java b/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java index 076ab7d..85be4e2 100644 --- a/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java +++ b/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java @@ -24,14 +24,14 @@ public class EmitterService { private static final Long DEFAULT_TIMEOUT = 1L * 60 * 1000; // 1분 - public SseEmitter subscribe(Long memberId) { - SseEmitter emitter = registerEmitter(memberId); - sendToClientIfNewAlarmExists(memberId); + public SseEmitter subscribe() { + Member member = memberService.getCurrentMember(); + SseEmitter emitter = registerEmitter(member.getMemberId()); + sendToClientIfNewAlarmExists(member); return emitter; } - private void sendToClientIfNewAlarmExists(Long memberId) { - Member member = memberService.getActiveMemberById(memberId); + private void sendToClientIfNewAlarmExists(Member member) { Boolean isMissedAlarms = alarmRepository.existsByReceiverAndIsReadFalse(member); if (isMissedAlarms.equals(true)) { sendToClient(member.getMemberId(), AlarmDefaultDataDto.from(true), "new sse alarm exists"); diff --git a/src/main/java/sws/songpin/global/config/SecurityConfig.java b/src/main/java/sws/songpin/global/config/SecurityConfig.java index a7cf9e1..23a7425 100644 --- a/src/main/java/sws/songpin/global/config/SecurityConfig.java +++ b/src/main/java/sws/songpin/global/config/SecurityConfig.java @@ -48,8 +48,7 @@ public WebSecurityCustomizer webSecurityCustomizer() { private static final String[] AUTH_WHITELIST = { "/signup", "/login", "/login/pw", "/token", "/mail/pw", - "/stats/**", "/map", "/map/period/**", "/map/playlists/**", - "/alarms/subscribe/**" + "/stats/**", "/map", "/map/period/**", "/map/playlists/**" }; @Bean From f961d377a18c103262f521b9835e2f6ba29f1a54 Mon Sep 17 00:00:00 2001 From: seohyun-lee Date: Fri, 16 Aug 2024 20:40:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20sse=20=ED=83=80=EC=9E=84=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EC=8B=9C=EA=B0=84=205=EB=B6=84=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sws/songpin/domain/alarm/service/EmitterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java b/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java index 85be4e2..7132370 100644 --- a/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java +++ b/src/main/java/sws/songpin/domain/alarm/service/EmitterService.java @@ -22,7 +22,7 @@ public class EmitterService { private final AlarmRepository alarmRepository; private final MemberService memberService; - private static final Long DEFAULT_TIMEOUT = 1L * 60 * 1000; // 1분 + private static final Long DEFAULT_TIMEOUT = 5L * 60 * 1000; // 5분 public SseEmitter subscribe() { Member member = memberService.getCurrentMember();