Skip to content

Commit

Permalink
#289 Feat: 알람 연결 해지 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-haeseung committed Dec 2, 2024
1 parent aae7d51 commit 5d513a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/")
@RequestMapping("/api/v2")
@Tag(name = "알람 API", description = "사용자 알람과 관련된 API를 제공합니다.")
public class AlertController {

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 확인

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5d513a9

Please sign in to comment.