diff --git a/src/main/java/com/codiary/backend/domain/alert/controller/AlertController.java b/src/main/java/com/codiary/backend/domain/alert/controller/AlertController.java index 56971e95..941bb6ae 100644 --- a/src/main/java/com/codiary/backend/domain/alert/controller/AlertController.java +++ b/src/main/java/com/codiary/backend/domain/alert/controller/AlertController.java @@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,7 +15,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v2/") +@RequestMapping("/api/v2") @Tag(name = "알람 API", description = "사용자 알람과 관련된 API를 제공합니다.") public class AlertController { @@ -29,4 +30,13 @@ public SseEmitter alert( return alertService.connect(memberId); } + @DeleteMapping("/disconnect") + @Operation(summary = "알람 해지") + public void disconnectAlert( + @AuthenticationPrincipal CustomMemberDetails memberDetails + ) { + Long memberId = memberDetails.getId(); + alertService.disconnect(memberId); + } + } diff --git a/src/main/java/com/codiary/backend/domain/alert/service/AlertService.java b/src/main/java/com/codiary/backend/domain/alert/service/AlertService.java index 0a10c4c5..564d4085 100644 --- a/src/main/java/com/codiary/backend/domain/alert/service/AlertService.java +++ b/src/main/java/com/codiary/backend/domain/alert/service/AlertService.java @@ -44,6 +44,12 @@ public SseEmitter connect(Long memberId) { return emitter; } + public void disconnect(Long memberId) { + SseEmitter emitter = emitterRepository.getEmitterByMemberId(memberId); + send(emitter, "disconnect", "알람 연결이 해지되었습니다.", memberId); + emitterRepository.deleteAllEmittersAboutMember(memberId); + } + public void sendBookmarkAlert(Bookmark bookmark) { // 알람 on/off 확인 diff --git a/src/main/java/com/codiary/backend/global/config/SecurityConfig.java b/src/main/java/com/codiary/backend/global/config/SecurityConfig.java index d8e65981..9deb1023 100644 --- a/src/main/java/com/codiary/backend/global/config/SecurityConfig.java +++ b/src/main/java/com/codiary/backend/global/config/SecurityConfig.java @@ -73,6 +73,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti // Calendar 관련 접근 // Project 관련 접근 // Category 관련 접근 + // 알람 관련 접근 + .requestMatchers("/api/v2/connect", "/api/v2/disconnect").permitAll() // 기타 관련 접근 .requestMatchers("/", "/api-docs/**", "/api-docs/swagger-config/*", "/swagger-ui/*", "/swagger-ui/**", "/v3/api-docs/**").permitAll() .anyRequest().authenticated()