Skip to content

Commit 66368fc

Browse files
authored
Merge pull request #50 from AI-Tutor-2024/develop
[ADD] 요약문 있는 노트만 조회 API 추가
2 parents c03415e + ae04ecc commit 66368fc

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jar {
1919
sourceSets {
2020
main {
2121
resources {
22+
srcDir 'src/main/resources'
2223
srcDir 'Server-v2.0-Config/yml'
23-
include 'application.yml'
2424
}
2525
}
2626
}

src/main/java/com/example/ai_tutor/domain/note/application/ProfessorNoteService.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,35 @@ public ResponseEntity<?> getAllNotesByFolder(UserPrincipal userPrincipal, Long f
204204
return ResponseEntity.ok(noteListRes);
205205
}
206206

207+
public ResponseEntity<?> getAllNotesByFolderWithSummary(UserPrincipal userPrincipal, Long folderId) {
208+
User user = getUser(userPrincipal);
209+
Folder folder = folderRepository.findById(folderId)
210+
.orElseThrow(() -> new IllegalArgumentException("폴더를 찾을 수 없습니다."));
211+
DefaultAssert.isTrue(user.equals(folder.getProfessor().getUser()), "사용자가 일치하지 않습니다.");
212+
213+
// summary가 있는 노트만 조회
214+
List<Note> notes = noteRepository
215+
.findAllByFolderAndSummaryIsNotNullOrderByCreatedAtDesc(folder);
216+
217+
List<ProfessorNoteListDetailRes> noteListDetailRes = notes.stream()
218+
.map(note -> ProfessorNoteListDetailRes.builder()
219+
.noteId(note.getNoteId())
220+
.title(note.getTitle())
221+
.createdAt(note.getCreatedAt().toLocalDate())
222+
.practiceSize(practiceRepository.countByNote(note))
223+
.code(note.getCode())
224+
.build())
225+
.toList();
226+
227+
NoteListRes<ProfessorNoteListDetailRes> noteListRes = NoteListRes.<ProfessorNoteListDetailRes>builder()
228+
.folderName(folder.getFolderName())
229+
.professor(folder.getProfessor().getUser().getName())
230+
.noteListDetailRes(noteListDetailRes)
231+
.build();
232+
return ResponseEntity.ok(noteListRes);
233+
}
234+
235+
207236
// 문제지 삭제
208237
@Transactional
209238
public ResponseEntity<?> deleteNoteById(UserPrincipal userPrincipal, Long noteId) {

src/main/java/com/example/ai_tutor/domain/note/domain/repository/NoteRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ public interface NoteRepository extends JpaRepository<Note, Long> {
1515
boolean existsByCode(String code);
1616

1717
Optional<Object> findByCode(String code);
18+
19+
List<Note> findAllByFolderAndSummaryIsNotNullOrderByCreatedAtDesc(Folder folder);
1820
}

src/main/java/com/example/ai_tutor/domain/note/presentation/NoteController.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.example.ai_tutor.domain.practice.dto.request.SavePracticeListReq;
99
import com.example.ai_tutor.domain.summary.application.SummaryService;
1010
import com.example.ai_tutor.domain.summary.dto.response.SummaryRes;
11+
import com.example.ai_tutor.global.aop.LogExecutionTime;
1112
import com.example.ai_tutor.global.config.security.token.UserPrincipal;
1213
import com.example.ai_tutor.global.payload.ErrorResponse;
1314
import com.example.ai_tutor.global.payload.Message;
@@ -78,6 +79,23 @@ public ResponseEntity<?> getAllNotes(
7879
return professorNoteService.getAllNotesByFolder(userPrincipal, folderId);
7980
}
8081

82+
// 노트 목록 조회
83+
@Operation(summary = "노트 목록 조회 중 API", security = { @SecurityRequirement(name = "BearerAuth") }, description = "로그인한 유저가 만든 요청한 폴더에 대한 강의 노트 목록을 조회하는 API입니다.")
84+
@ApiResponses(value = {
85+
86+
@ApiResponse(responseCode = "200", description = "강의 노트 목록 조회 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = NoteListRes.class) ) } ),
87+
@ApiResponse(responseCode = "400", description = "강의 노트 목록 조회 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
88+
})
89+
@GetMapping("/summary")
90+
public ResponseEntity<?> getAllNotesByFolderWithSummary(
91+
@AuthenticationPrincipal UserPrincipal userPrincipal,
92+
@PathVariable Long folderId
93+
) {
94+
return professorNoteService.getAllNotesByFolderWithSummary(userPrincipal, folderId);
95+
}
96+
97+
98+
8199
@Operation(summary = "노트 단일 조회 API", security = { @SecurityRequirement(name = "BearerAuth") }, description = "로그인한 유저가 만든 특정 강의 노트 목록을 조회하는 API입니다.")
82100
@ApiResponses(value = {
83101
@ApiResponse(responseCode = "200", description = "강의 노트 목록 조회 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = NoteListRes.class) ) } ),
@@ -111,6 +129,7 @@ public ResponseEntity<?> deleteNote(
111129
@ApiResponse(responseCode = "200", description = "STT 변환 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class)) }),
112130
@ApiResponse(responseCode = "400", description = "STT 변환 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)) }),
113131
})
132+
@LogExecutionTime("STT 변환 요청")
114133
@PostMapping(value = "/{noteId}/stt", consumes = "multipart/form-data")
115134
public ResponseEntity<?> convertSpeechToText(
116135
// @Parameter(description = "Access Token을 입력해주세요.", required = false) @AuthenticationPrincipal UserPrincipal userPrincipal,
@@ -128,7 +147,7 @@ public ResponseEntity<?> convertSpeechToText(
128147
}
129148
} catch (Exception e) {
130149
log.error("STT 변환 중 오류 발생: {}", e.getMessage(), e);
131-
return ResponseEntity.badRequest().body("STT 변환 실패: " + e.getMessage());
150+
return ResponseEntity.badRequest().body("STT 변환 실패: " + e.getMessage());
132151
}
133152
}
134153

@@ -144,6 +163,7 @@ public ResponseEntity<?> convertSpeechToText(
144163
content = @Content(mediaType = "application/json"))
145164
})
146165
@PreAuthorize("isAuthenticated()")
166+
@LogExecutionTime("노트 요약본 생성")
147167
@PostMapping("/{noteId}/summaries")
148168
public Mono<ResponseEntity<SummaryRes>> createSummary(
149169
@Parameter(description = "note id를 입력해주세요", required = true) @PathVariable Long noteId,

0 commit comments

Comments
 (0)