-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/ddingdong/ddingdongBE/sse/api/SseConnectionApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ddingdong.ddingdongBE.sse.api; | ||
|
||
import ddingdong.ddingdongBE.auth.PrincipalDetails; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
|
||
@Tag(name = "SSE", description = "SSE subscribe API") | ||
@RequestMapping("/server/sse") | ||
public interface SseConnectionApi { | ||
|
||
@Operation(summary = "SSE 구독") | ||
@ApiResponse(responseCode = "200", description = "활동 보고서 전체 조회 성공") | ||
@ResponseStatus(HttpStatus.OK) | ||
@SecurityRequirement(name = "AccessToken") | ||
@GetMapping(value = "/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
SseEmitter subscribe(@AuthenticationPrincipal PrincipalDetails principalDetails); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/ddingdong/ddingdongBE/sse/controller/SseConnectionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ddingdong.ddingdongBE.sse.controller; | ||
|
||
import ddingdong.ddingdongBE.auth.PrincipalDetails; | ||
import ddingdong.ddingdongBE.domain.user.entity.User; | ||
import ddingdong.ddingdongBE.sse.api.SseConnectionApi; | ||
import ddingdong.ddingdongBE.sse.service.SseConnectionService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class SseConnectionController implements SseConnectionApi { | ||
|
||
private final SseConnectionService sseConnectionService; | ||
|
||
@Override | ||
public SseEmitter subscribe(PrincipalDetails principalDetails) { | ||
User user = principalDetails.getUser(); | ||
Long timeout = 60L * 1000; // 1분 (60초 * 1000밀리초) | ||
return sseConnectionService.subscribe(user.getAuthId(), timeout); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters