Skip to content

Commit

Permalink
Merge branch 'feat/alarm' into test-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
seohyun-lee committed Aug 16, 2024
2 parents 6e06728 + f961d37 commit 064075b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SseEmitter> 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<SseEmitter> subscribe() {
return ResponseEntity.ok(emitterService.subscribe());
}

@Operation(summary = "알림 목록 조회 및 읽음 처리", description = "알림 목록을 조회하고 읽음 처리합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ 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(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");
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/sws/songpin/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 064075b

Please sign in to comment.