diff --git a/src/main/java/com/smart/watchboard/controller/AudioFileController.java b/src/main/java/com/smart/watchboard/controller/AudioFileController.java index 1919ace..dc99217 100644 --- a/src/main/java/com/smart/watchboard/controller/AudioFileController.java +++ b/src/main/java/com/smart/watchboard/controller/AudioFileController.java @@ -109,7 +109,7 @@ public ResponseEntity getAudioFile(@PathVariable(value = "documentID") long d } @PostMapping("/testffff") - public ResponseEntity test(@RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException { + public ResponseEntity test(@RequestParam("audioFile") MultipartFile audioFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException { String body = """ { "segments":[ @@ -144,14 +144,20 @@ public ResponseEntity test(@RequestHeader("Authorization") String accessToken ] } """; - ResponseEntity response1 = new ResponseEntity<>(body, HttpStatus.OK); - List data = sttService.getSTTData(response1); - System.out.println(data.get(0).getText()); - lectureNoteService.createLectureNote(100L, data, "aa"); - String path = "naver.com"; - SttDto body2 = fileService.createResponseBody(path, data); - ResponseEntity ss = new ResponseEntity<>(body2, HttpStatus.OK); - return ss; +// ResponseEntity response1 = new ResponseEntity<>(body, HttpStatus.OK); +// List data = sttService.getSTTData(response1); +// System.out.println(data.get(0).getText()); +// lectureNoteService.createLectureNote(100L, data, "aa"); +// String path = "naver.com"; +// SttDto body2 = fileService.createResponseBody(path, data); +// ResponseEntity ss = new ResponseEntity<>(body2, HttpStatus.OK); +// return ss; + S3Dto s3Dto = new S3Dto(audioFile, 26L); + String path = awsS3Uploader.uploadFile(s3Dto); + int startIndex = path.indexOf("application/pdf/") + "application/pdf/".length(); + String extractedString = path.substring(startIndex); + System.out.println(extractedString); + return new ResponseEntity<>(HttpStatus.OK); } } diff --git a/src/main/java/com/smart/watchboard/controller/GraphController.java b/src/main/java/com/smart/watchboard/controller/GraphController.java index 079d758..3de504d 100644 --- a/src/main/java/com/smart/watchboard/controller/GraphController.java +++ b/src/main/java/com/smart/watchboard/controller/GraphController.java @@ -63,7 +63,7 @@ public ResponseEntity updateKeywords(@PathVariable(value = "documentID") long @GetMapping("/documents/{documentID}/mindmap/keyword/{keywordLabel}") @Operation(summary = "키워드 질문", description = "키워드 AI에 질문") public ResponseEntity getAnswer(@PathVariable(value = "documentID") long documentId, @PathVariable String keywordLabel, @RequestHeader("Authorization") String accessToken) throws JsonProcessingException { - ResponseEntity responseEntity = mindmapService.getKeywordAnswer(documentId, keywordLabel); + ResponseEntity responseEntity = requestService.requestAnswer(documentId, keywordLabel); return new ResponseEntity<>(responseEntity, HttpStatus.OK); } diff --git a/src/main/java/com/smart/watchboard/controller/LearningFileController.java b/src/main/java/com/smart/watchboard/controller/LearningFileController.java index 70c6493..8aecbb4 100644 --- a/src/main/java/com/smart/watchboard/controller/LearningFileController.java +++ b/src/main/java/com/smart/watchboard/controller/LearningFileController.java @@ -6,10 +6,7 @@ import com.smart.watchboard.dto.FileDto; import com.smart.watchboard.dto.KeywordsDto; import com.smart.watchboard.dto.S3Dto; -import com.smart.watchboard.service.FileService; -import com.smart.watchboard.service.MindmapService; -import com.smart.watchboard.service.RequestService; -import com.smart.watchboard.service.WhiteboardService; +import com.smart.watchboard.service.*; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,12 +30,15 @@ public class LearningFileController { private final FileService fileService; private final RequestService requestService; private final WhiteboardService whiteboardService; + private final SummaryService summaryService; @PostMapping("/{documentID}/pdf") public ResponseEntity uploadLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException { S3Dto s3Dto = new S3Dto(pdfFile, documentId); String path = awsS3Uploader.uploadFile(s3Dto); ResponseEntity responseEntity = requestService.requestPdfKeywords(path); + String summary = requestService.requestPdfSummary(path); + summaryService.createSummary(documentId, summary); whiteboardService.setDataType(documentId, "pdf"); return new ResponseEntity<>(responseEntity.getBody(), HttpStatus.OK); diff --git a/src/main/java/com/smart/watchboard/service/MindmapService.java b/src/main/java/com/smart/watchboard/service/MindmapService.java index 17703ff..defeb18 100644 --- a/src/main/java/com/smart/watchboard/service/MindmapService.java +++ b/src/main/java/com/smart/watchboard/service/MindmapService.java @@ -27,7 +27,7 @@ public class MindmapService { private final MindmapRepository mindmapRepository; private final WhiteboardService whiteboardService; - private final RequestService requestService; + //private final RequestService requestService; public void createMindmap(ResponseEntity responseEntity, Long documentId) throws JsonProcessingException { Document document = whiteboardService.findDoc(documentId); @@ -80,7 +80,7 @@ public void updateKeywords(KeywordsDto keywordsDto, Long documentId) { mindmapRepository.save(updatedMindmap); } - public ResponseEntity getKeywordAnswer(Long documentId, String keywordLabel) throws JsonProcessingException { - return requestService.requestAnswer(documentId, keywordLabel); - } +// public ResponseEntity getKeywordAnswer(Long documentId, String keywordLabel) throws JsonProcessingException { +// return requestService.requestAnswer(documentId, keywordLabel); +// } } diff --git a/src/main/java/com/smart/watchboard/service/RequestService.java b/src/main/java/com/smart/watchboard/service/RequestService.java index 2b91529..cb3f322 100644 --- a/src/main/java/com/smart/watchboard/service/RequestService.java +++ b/src/main/java/com/smart/watchboard/service/RequestService.java @@ -28,6 +28,9 @@ public class RequestService { private final SummaryService summaryService; public ResponseEntity requestPdfKeywords(String filePath) { + int startIndex = filePath.indexOf("application/pdf/") + "application/pdf/".length(); + String fileName = filePath.substring(startIndex); + RestTemplate restTemplate = new RestTemplate(); String url = aiUrl + "/keywords"; // 요청 헤더 추가 @@ -42,7 +45,7 @@ public ResponseEntity requestPdfKeywords(String filePath) { "db": "s3" } } - """.formatted(filePath); + """.formatted(fileName); HttpEntity requestEntity = new HttpEntity<>(requestBody, headers); // 요청 보내기 @@ -77,7 +80,10 @@ public ResponseEntity requestSTTKeywords(String text) { return responseEntity; } - public ResponseEntity requestPdfSummary(String filePath) { + public String requestPdfSummary(String filePath) throws JsonProcessingException { + int startIndex = filePath.indexOf("application/pdf/") + "application/pdf/".length(); + String fileName = filePath.substring(startIndex); + RestTemplate restTemplate = new RestTemplate(); String url = aiUrl + "/summary"; //String url = "http://echo.jsontest.com/key/value/one/two"; @@ -93,13 +99,17 @@ public ResponseEntity requestPdfSummary(String filePath) { "db": "s3" } } - """.formatted(filePath); + """.formatted(fileName); HttpEntity requestEntity = new HttpEntity<>(requestBody, headers); // 요청 보내기 ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); //ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); - return responseEntity; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(responseEntity.getBody()); + String text = jsonNode.get("summary").asText(); + + return text; } public String requestSTTSummary(String sttResult) throws JsonProcessingException {