Skip to content

Commit

Permalink
Merge pull request #29 from SWM-SMART/feat/#28
Browse files Browse the repository at this point in the history
키워드 업데이트 구현
  • Loading branch information
noparamin authored Nov 3, 2023
2 parents 33814b2 + 8ffc62d commit 7e6d884
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<?> uploadAudioFile(@PathVariable(value = "documentID") lon
lectureNoteService.createLectureNote(documentId, data);
//noteService.createNote(documentId, sttResult);

// STT 키워드 요청
// STT 키워드 요청 마인드맵 요청 -> 마인드맵 생성
ResponseEntity<String> responseEntity = requestService.requestSTTKeywords(sttResult);

// 요약본 요청
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/smart/watchboard/controller/GraphController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.smart.watchboard.common.support.AudioConcatenator;
import com.smart.watchboard.common.support.AwsS3Uploader;
import com.smart.watchboard.dto.KeywordsDto;
import com.smart.watchboard.service.FileService;
import com.smart.watchboard.service.MindmapService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,17 +20,17 @@
import java.io.IOException;

@RestController
@RequestMapping("/graph")
@Tag(name = "그래프 API", description = "그래프 관련 API(mock)")
@RequiredArgsConstructor
@Slf4j
public class GraphController {

private final AwsS3Uploader awsS3Uploader;
private final AudioConcatenator audioConcatenator;
private final MindmapService mindmapService;
private final String aiServerUrl = "";

@PostMapping("/{documentID}")
@PostMapping("/graph/{documentID}")
@Operation(summary = "마인드맵 생성", description = "음성 데이터를 받아 ai 서버에 마인드맵 요청한다.")
public ResponseEntity<?> getMindmap(@PathVariable(value = "documentID") long documentId, @RequestParam("audioFile") MultipartFile audioFile, @RequestParam(value = "fileID", required = false) Long fileId, @RequestHeader("Authorization") String accessToken) {
//awsS3Uploader.uploadFile(audioFile, documentId, fileId);
Expand All @@ -37,6 +39,14 @@ public ResponseEntity<?> getMindmap(@PathVariable(value = "documentID") long doc
return new ResponseEntity<>("{\"root\":1,\"keywords\":[\"나는\",\"eat\",\"food\",\"today\"],\"graph\":{\"1\":[0,2],\"2\":[3]}}", HttpStatus.OK);
}

@PutMapping("/documents/{documentID}/mindmap/keyword")
@Operation(summary = "키워드 업데이트", description = "키워드 추가 및 삭제")
public ResponseEntity<?> updateKeywords(@PathVariable(value = "documentID") long documentId, @RequestHeader("Authorization") String accessToken, @RequestBody KeywordsDto keywordsDto) {
mindmapService.updateKeywords(keywordsDto, documentId);

return new ResponseEntity<>(HttpStatus.OK);
}

@PostMapping("/abc")
public ResponseEntity<?> test(@RequestParam("audioFile1") MultipartFile audioFile1, @RequestParam(value = "fileID", required = false) Long fileId, @RequestParam(value = "documentID") Long documentId) throws UnsupportedAudioFileException, IOException {
audioConcatenator.concatenateAudioFiles(audioFile1, documentId, fileId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.smart.watchboard.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.smart.watchboard.common.support.AwsS3Uploader;
import com.smart.watchboard.domain.File;
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 io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +19,8 @@

import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/documents")
Expand All @@ -28,7 +33,7 @@ public class LearningFileController {
private final RequestService requestService;

@PostMapping("/{documentID}/pdf")
public ResponseEntity<?> uploadLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdfFile") MultipartFile pdfFile, @RequestParam(value = "fileID", required = false) Long fileId, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
public ResponseEntity<?> uploadLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestParam(value = "fileID", required = false) Long fileId, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
S3Dto s3Dto = new S3Dto(pdfFile, documentId, fileId);
String path = awsS3Uploader.uploadFile(s3Dto);
ResponseEntity<String> responseEntity = requestService.requestPdfKeywords(path);
Expand All @@ -37,7 +42,7 @@ public ResponseEntity<?> uploadLearningFile(@PathVariable(value = "documentID")
}

@PutMapping("/{documentID}/pdf")
public ResponseEntity<?> updateLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdfFile") MultipartFile pdfFile, @RequestParam(value = "fileID", required = false) Long fileId, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
public ResponseEntity<?> updateLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestParam(value = "fileID", required = false) Long fileId, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
S3Dto s3Dto = new S3Dto(pdfFile, documentId, fileId);
String path = awsS3Uploader.uploadFile(s3Dto);
ResponseEntity<String> responseEntity = requestService.requestPdfKeywords(path);
Expand All @@ -61,13 +66,32 @@ public ResponseEntity<?> getLearningFile(@PathVariable(value = "documentID") lon
}

@GetMapping("/test")
public ResponseEntity<?> test(@RequestHeader("Authorization") String accessToken) {
public ResponseEntity<?> test(@RequestHeader("Authorization") String accessToken) throws JsonProcessingException {
//String path = "abcd";
//ResponseEntity<String> responseEntity = requestService.requestPdfKeywords(path);
String body = fileService.getPdfUrl(4L);
System.out.println(body);
// String xx = """
// {"root":1,"keywords":["나는","eat","food","today"],"graph":{"1":[0,2],"2":[3]}}
// """;

return new ResponseEntity<>(body, HttpStatus.OK);
String xx = """
{
"add": ["추가할", "키워드", "목록"],
"delete": ["eat"],
}
""";
// List<String> add = new ArrayList<>();
// add.add("추가할");
// add.add("키워드");
// List<String> delete = new ArrayList<>();
// delete.add("eat");
// KeywordsDto keywordsDto = new KeywordsDto(add, delete);
//ResponseEntity<String> entity = new ResponseEntity<>(xx, HttpStatus.OK);
// mindmapService.updateKeywords(keywordsDto, 11L);
//mindmapService.createMindmap(entity, 11L, "pdf");
//String body = fileService.getPdfUrl(4L);
//System.out.println(body);

return new ResponseEntity<>("", HttpStatus.OK);

}
}
18 changes: 18 additions & 0 deletions src/main/java/com/smart/watchboard/dto/KeywordsDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.smart.watchboard.dto;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class KeywordsDto {
private List<String> add;
private List<String> delete;

public KeywordsDto(List<String> add, List<String> delete) {
this.add = add;
this.delete = delete;
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/smart/watchboard/service/MindmapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smart.watchboard.domain.Document;
import com.smart.watchboard.domain.Mindmap;
import com.smart.watchboard.dto.KeywordsDto;
import com.smart.watchboard.dto.MindmapDto;
import com.smart.watchboard.repository.MindmapRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,6 +15,7 @@
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -61,4 +63,20 @@ public MindmapDto getMindmap(Long documentId) {
public void deleteMindmap(Long documentId) {
mindmapRepository.deleteByDocumentId(documentId);
}

public void updateKeywords(KeywordsDto keywordsDto, Long documentId) {
Optional<Mindmap> mindmap = mindmapRepository.findByDocumentId(documentId);
List<String> keywords = mindmap.get().getKeywords();
List<String> addKeywords = keywordsDto.getAdd();
List<String> deleteKeywords = keywordsDto.getDelete();

List<String> newKeywords = new ArrayList<>(keywords);
newKeywords.removeAll(deleteKeywords);
newKeywords.addAll(addKeywords);

Mindmap updatedMindmap = mindmap.orElse(null);
updatedMindmap.setKeywords(newKeywords);

mindmapRepository.save(updatedMindmap);
}
}

0 comments on commit 7e6d884

Please sign in to comment.