From 1948e992d544f83910a167904aa6adcb72962b69 Mon Sep 17 00:00:00 2001 From: kms Date: Wed, 22 Nov 2023 01:20:59 +0900 Subject: [PATCH 1/5] :wrench: fix: add extractAccessToken before extractUserId #70 --- .../watchboard/controller/AudioFileController.java | 3 ++- .../controller/LearningFileController.java | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/smart/watchboard/controller/AudioFileController.java b/src/main/java/com/smart/watchboard/controller/AudioFileController.java index 24efb22..d5fadb9 100644 --- a/src/main/java/com/smart/watchboard/controller/AudioFileController.java +++ b/src/main/java/com/smart/watchboard/controller/AudioFileController.java @@ -47,7 +47,8 @@ public class AudioFileController { @PostMapping("/{documentID}/audio") public ResponseEntity uploadAudioFile(@PathVariable(value = "documentID") long documentId, @RequestParam("audio") MultipartFile audioFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException, DocumentException { - Optional id = jwtService.extractUserId(accessToken); + String extractedAccessToken = jwtService.extractAccessToken(accessToken); + Optional id = jwtService.extractUserId(extractedAccessToken); Long userId = id.orElse(null); // s3에 오디오 파일 저장 diff --git a/src/main/java/com/smart/watchboard/controller/LearningFileController.java b/src/main/java/com/smart/watchboard/controller/LearningFileController.java index 65b5de8..2052393 100644 --- a/src/main/java/com/smart/watchboard/controller/LearningFileController.java +++ b/src/main/java/com/smart/watchboard/controller/LearningFileController.java @@ -38,7 +38,8 @@ public class LearningFileController { @PostMapping("/{documentID}/pdf") public ResponseEntity uploadLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException { - Optional id = jwtService.extractUserId(accessToken); + String extractedAccessToken = jwtService.extractAccessToken(accessToken); + Optional id = jwtService.extractUserId(extractedAccessToken); Long userId = id.orElse(null); if (!checkPageLimit(countPdfPage(pdfFile))) { @@ -47,16 +48,9 @@ public ResponseEntity uploadLearningFile(@PathVariable(value = "documentID") S3Dto s3Dto = new S3Dto(pdfFile, documentId, userId, "pdf"); String path = awsS3Uploader.uploadFile(s3Dto); - //sseService.notifyKeywords(documentId, path); - //sseService.notifySummary(documentId, path); -// ResponseEntity responseEntity = requestService.requestPdfKeywords(path); -// keywordService.createKeywords(responseEntity, documentId); -// -// ResponseEntity summary = requestService.requestPdfSummary(path); -// summaryService.createSummary(documentId, summary.getBody().getSummary()); + whiteboardService.setDataType(documentId, "pdf"); - //return new ResponseEntity<>(responseEntity.getBody(), HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK); } From 3c05847c0ff1b5c48fdd9e5ddcdc94acafeec865 Mon Sep 17 00:00:00 2001 From: kms Date: Wed, 22 Nov 2023 01:31:48 +0900 Subject: [PATCH 2/5] :sparkles: fix: create getting all documentId #72 --- .../com/smart/watchboard/repository/EmitterRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/smart/watchboard/repository/EmitterRepository.java b/src/main/java/com/smart/watchboard/repository/EmitterRepository.java index c98bffd..1b2c26f 100644 --- a/src/main/java/com/smart/watchboard/repository/EmitterRepository.java +++ b/src/main/java/com/smart/watchboard/repository/EmitterRepository.java @@ -4,8 +4,10 @@ import org.springframework.stereotype.Repository; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; @Repository @RequiredArgsConstructor @@ -23,4 +25,9 @@ public void deleteById(Long id) { public SseEmitter get(Long id) { return emitters.get(id); } + + public List getAllKeys() { + return emitters.keySet().stream() + .collect(Collectors.toList()); + } } From 2a2f0341eefd6ca77429822d4cccbef885908553 Mon Sep 17 00:00:00 2001 From: kms Date: Wed, 22 Nov 2023 01:33:12 +0900 Subject: [PATCH 3/5] :sparkles: feat: create a feature to send notifications to all subscribers #72 --- .../smart/watchboard/service/SseService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/smart/watchboard/service/SseService.java b/src/main/java/com/smart/watchboard/service/SseService.java index 94cd721..adf383c 100644 --- a/src/main/java/com/smart/watchboard/service/SseService.java +++ b/src/main/java/com/smart/watchboard/service/SseService.java @@ -51,6 +51,24 @@ public void notify(Long documentId, List keywords) { sendToClient(documentId, keywords); } + public void notifyCycle() { + sendCycle(); + } + + private void sendCycle() { + List keys = emitterRepository.getAllKeys(); + for (Long documentId : keys) { + SseEmitter emitter = emitterRepository.get(documentId); + try { + emitter.send(SseEmitter.event().id(String.valueOf(documentId)).name("ping").data("ping")); + } catch (IOException exception) { + emitterRepository.deleteById(documentId); + emitter.completeWithError(exception); + } + + } + } + private void sendToClientFirst(Long documentId, Object data) { SseEmitter emitter = emitterRepository.get(documentId); if (emitter != null) { From 344a3861e8faf1c29b213e0f4757567facfeab6a Mon Sep 17 00:00:00 2001 From: kms Date: Wed, 22 Nov 2023 01:35:06 +0900 Subject: [PATCH 4/5] :sparkles: feat: create a feature to send notifications to all subscribers every 30 seconds #72 --- .../common/support/ScheduledTask.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/smart/watchboard/common/support/ScheduledTask.java diff --git a/src/main/java/com/smart/watchboard/common/support/ScheduledTask.java b/src/main/java/com/smart/watchboard/common/support/ScheduledTask.java new file mode 100644 index 0000000..2dd5c78 --- /dev/null +++ b/src/main/java/com/smart/watchboard/common/support/ScheduledTask.java @@ -0,0 +1,17 @@ +package com.smart.watchboard.common.support; + +import com.smart.watchboard.service.SseService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ScheduledTask { + private final SseService sseService; + + @Scheduled(fixedRate = 30000) + public void executeNotifyTask() { + sseService.notifyCycle(); + } +} From 4ad41bc5ca4fa45223975aeeb6bdfee134d5986e Mon Sep 17 00:00:00 2001 From: kms Date: Wed, 22 Nov 2023 01:35:35 +0900 Subject: [PATCH 5/5] :sparkles: feat: add EnableScheduling #72 --- src/main/java/com/smart/watchboard/WatchboardApplication.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/smart/watchboard/WatchboardApplication.java b/src/main/java/com/smart/watchboard/WatchboardApplication.java index 8eae708..9f027da 100644 --- a/src/main/java/com/smart/watchboard/WatchboardApplication.java +++ b/src/main/java/com/smart/watchboard/WatchboardApplication.java @@ -2,7 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + @SpringBootApplication +@EnableScheduling public class WatchboardApplication { public static void main(String[] args) {