From 7b2e4cffe99c993b33f7921a4b111da762f7ab6d Mon Sep 17 00:00:00 2001 From: YugyeomGhim Date: Tue, 12 Nov 2024 01:26:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20member=20=EA=B0=80=20=EC=98=81=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=BB=A8=ED=85=8D=EC=8A=A4=ED=8A=B8=EC=97=90=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20?= =?UTF-8?q?=EC=B1=84=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=ED=95=B4=20=EC=83=9D?= =?UTF-8?q?=EA=B8=B0=EB=8A=94=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/AnnotationQueryService.java | 5 ++- .../application/AnnotationService.java | 11 +++-- .../presentation/AnnotationController.java | 17 ++++---- .../java/notai/auth/AuthArgumentResolver.java | 5 +-- .../document/application/DocumentService.java | 27 +++++++----- .../presentation/DocumentController.java | 18 ++++---- .../application/FolderQueryService.java | 10 ++--- .../folder/application/FolderService.java | 24 +++++++---- .../folder/presentation/FolderController.java | 43 +++++++++---------- .../llm/application/LlmTaskQueryService.java | 14 ++++-- .../llm/presentation/LlmTaskController.java | 16 +++---- .../member/presentation/MemberController.java | 4 +- .../response/MemberFindResponse.java | 6 +-- .../ocr/application/OCRQueryService.java | 6 ++- .../notai/ocr/presentation/OCRController.java | 4 +- .../application/PageRecordingService.java | 6 ++- .../presentation/PageRecordingController.java | 4 +- .../application/RecordingService.java | 5 ++- .../presentation/RecordingController.java | 4 +- .../AnnotationControllerTest.java | 10 ++--- .../application/FolderQueryServiceTest.java | 4 +- .../application/LlmTaskQueryServiceTest.java | 26 +++++------ .../application/PageRecordingServiceTest.java | 8 +++- .../application/RecordingServiceTest.java | 12 ++++-- 24 files changed, 167 insertions(+), 122 deletions(-) diff --git a/src/main/java/notai/annotation/application/AnnotationQueryService.java b/src/main/java/notai/annotation/application/AnnotationQueryService.java index 62aa952..580c274 100644 --- a/src/main/java/notai/annotation/application/AnnotationQueryService.java +++ b/src/main/java/notai/annotation/application/AnnotationQueryService.java @@ -8,6 +8,7 @@ import notai.document.domain.Document; import notai.document.domain.DocumentRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,12 +23,14 @@ public class AnnotationQueryService { private final AnnotationRepository annotationRepository; private final DocumentRepository documentRepository; + private final MemberRepository memberRepository; @Transactional(readOnly = true) public List getAnnotationsByDocumentAndPageNumbers( - Member member, Long documentId, List pageNumbers + Long memberId, Long documentId, List pageNumbers ) { Document document = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); document.validateOwner(member); List annotations = annotationRepository.findByDocumentIdAndPageNumberIn(documentId, pageNumbers); diff --git a/src/main/java/notai/annotation/application/AnnotationService.java b/src/main/java/notai/annotation/application/AnnotationService.java index 983c0c3..0be72dd 100644 --- a/src/main/java/notai/annotation/application/AnnotationService.java +++ b/src/main/java/notai/annotation/application/AnnotationService.java @@ -7,6 +7,7 @@ import notai.document.domain.Document; import notai.document.domain.DocumentRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +17,14 @@ public class AnnotationService { private final AnnotationRepository annotationRepository; private final DocumentRepository documentRepository; + private final MemberRepository memberRepository; @Transactional public AnnotationResponse createAnnotation( - Member member, Long documentId, int pageNumber, int x, int y, int width, int height, String content + Long memberId, Long documentId, int pageNumber, int x, int y, int width, int height, String content ) { Document document = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); document.validateOwner(member); Annotation annotation = new Annotation(document, pageNumber, x, y, width, height, content); @@ -31,9 +34,10 @@ public AnnotationResponse createAnnotation( @Transactional public AnnotationResponse updateAnnotation( - Member member, Long documentId, Long annotationId, int x, int y, int width, int height, String content + Long memberId, Long documentId, Long annotationId, int x, int y, int width, int height, String content ) { Document document = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); document.validateOwner(member); Annotation annotation = annotationRepository.getById(annotationId); annotation.updateAnnotation(x, y, width, height, content); @@ -41,8 +45,9 @@ public AnnotationResponse updateAnnotation( } @Transactional - public void deleteAnnotation(Member member, Long documentId, Long annotationId) { + public void deleteAnnotation(Long memberId, Long documentId, Long annotationId) { Document document = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); document.validateOwner(member); Annotation annotation = annotationRepository.getById(annotationId); annotationRepository.delete(annotation); diff --git a/src/main/java/notai/annotation/presentation/AnnotationController.java b/src/main/java/notai/annotation/presentation/AnnotationController.java index f06ea77..583ef95 100644 --- a/src/main/java/notai/annotation/presentation/AnnotationController.java +++ b/src/main/java/notai/annotation/presentation/AnnotationController.java @@ -7,7 +7,6 @@ import notai.annotation.presentation.request.CreateAnnotationRequest; import notai.annotation.presentation.response.AnnotationResponse; import notai.auth.Auth; -import notai.member.domain.Member; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -24,11 +23,11 @@ public class AnnotationController { @PostMapping public ResponseEntity createAnnotation( - @Auth Member member, @PathVariable Long documentId, @RequestBody @Valid CreateAnnotationRequest request + @Auth Long memberId, @PathVariable Long documentId, @RequestBody @Valid CreateAnnotationRequest request ) { AnnotationResponse response = annotationService.createAnnotation( - member, + memberId, documentId, request.pageNumber(), request.x(), @@ -44,10 +43,10 @@ public ResponseEntity createAnnotation( @GetMapping public ResponseEntity> getAnnotations( - @Auth Member member, @PathVariable Long documentId, @RequestParam List pageNumbers + @Auth Long memberId, @PathVariable Long documentId, @RequestParam List pageNumbers ) { List response = annotationQueryService.getAnnotationsByDocumentAndPageNumbers( - member, + memberId, documentId, pageNumbers ); @@ -57,14 +56,14 @@ public ResponseEntity> getAnnotations( @PutMapping("/{annotationId}") public ResponseEntity updateAnnotation( - @Auth Member member, + @Auth Long memberId, @PathVariable Long documentId, @PathVariable Long annotationId, @RequestBody @Valid CreateAnnotationRequest request ) { AnnotationResponse response = annotationService.updateAnnotation( - member, + memberId, documentId, annotationId, request.x(), @@ -79,10 +78,10 @@ public ResponseEntity updateAnnotation( @DeleteMapping("/{annotationId}") public ResponseEntity deleteAnnotation( - @Auth Member member, @PathVariable Long documentId, @PathVariable Long annotationId + @Auth Long memberId, @PathVariable Long documentId, @PathVariable Long annotationId ) { - annotationService.deleteAnnotation(member, documentId, annotationId); + annotationService.deleteAnnotation(memberId, documentId, annotationId); return new ResponseEntity<>(HttpStatus.OK); } } diff --git a/src/main/java/notai/auth/AuthArgumentResolver.java b/src/main/java/notai/auth/AuthArgumentResolver.java index 10a1b0c..d832eba 100644 --- a/src/main/java/notai/auth/AuthArgumentResolver.java +++ b/src/main/java/notai/auth/AuthArgumentResolver.java @@ -25,8 +25,7 @@ public boolean supportsParameter(MethodParameter parameter) { } @Override - @Transactional(readOnly = true) - public Member resolveArgument( + public Long resolveArgument( MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @@ -34,6 +33,6 @@ public Member resolveArgument( ) { HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); Long memberId = (Long) request.getAttribute("memberId"); - return memberRepository.getById(memberId); + return memberRepository.getById(memberId).getId(); } } diff --git a/src/main/java/notai/document/application/DocumentService.java b/src/main/java/notai/document/application/DocumentService.java index cb438a6..028e750 100644 --- a/src/main/java/notai/document/application/DocumentService.java +++ b/src/main/java/notai/document/application/DocumentService.java @@ -10,6 +10,7 @@ import notai.folder.domain.Folder; import notai.folder.domain.FolderRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.ocr.application.OCRService; import notai.pdf.PdfService; import notai.pdf.result.PdfSaveResult; @@ -28,32 +29,33 @@ public class DocumentService { private final OCRService ocrService; private final DocumentRepository documentRepository; private final FolderRepository folderRepository; + private final MemberRepository memberRepository; private static final Long ROOT_FOLDER_ID = -1L; - public DocumentSaveResult saveDocument( - Member member, Long folderId, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest + Long memberId, Long folderId, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest ) { PdfSaveResult pdfSaveResult = pdfService.savePdf(pdfFile); - Document document = saveAndReturnDocument(member, folderId, documentSaveRequest, pdfSaveResult); + Document document = saveAndReturnDocument(memberId, folderId, documentSaveRequest, pdfSaveResult); ocrService.saveOCR(document, pdfSaveResult.pdf()); return DocumentSaveResult.of(document.getId(), document.getName(), document.getUrl()); } public DocumentSaveResult saveRootDocument( - Member member, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest + Long memberId, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest ) { PdfSaveResult pdfSaveResult = pdfService.savePdf(pdfFile); - Document document = saveAndReturnRootDocument(member, documentSaveRequest, pdfSaveResult); + Document document = saveAndReturnRootDocument(memberId, documentSaveRequest, pdfSaveResult); ocrService.saveOCR(document, pdfSaveResult.pdf()); return DocumentSaveResult.of(document.getId(), document.getName(), document.getUrl()); } public DocumentUpdateResult updateDocument( - Member member, Long folderId, Long documentId, DocumentUpdateRequest documentUpdateRequest + Long memberId, Long folderId, Long documentId, DocumentUpdateRequest documentUpdateRequest ) { Document document = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); document.validateOwner(member); @@ -66,9 +68,10 @@ public DocumentUpdateResult updateDocument( } public void deleteDocument( - Member member, Long folderId, Long documentId + Long memberId, Long folderId, Long documentId ) { Document document = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); document.validateOwner(member); @@ -80,17 +83,18 @@ public void deleteDocument( } public void deleteAllByFolder( - Member member, Folder folder + Long memberId, Folder folder ) { List documents = documentRepository.findAllByFolderId(folder.getId()); for (Document document : documents) { - deleteDocument(member, folder.getId(), document.getId()); + deleteDocument(memberId, folder.getId(), document.getId()); } } private Document saveAndReturnDocument( - Member member, Long folderId, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult + Long memberId, Long folderId, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult ) { + Member member = memberRepository.getById(memberId); Folder folder = folderRepository.getById(folderId); Document document = new Document(folder, member, @@ -102,8 +106,9 @@ private Document saveAndReturnDocument( } private Document saveAndReturnRootDocument( - Member member, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult + Long memberId, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult ) { + Member member = memberRepository.getById(memberId); Document document = new Document(member, documentSaveRequest.name(), pdfSaveResult.pdfUrl(), diff --git a/src/main/java/notai/document/presentation/DocumentController.java b/src/main/java/notai/document/presentation/DocumentController.java index 548cfc2..b32bd52 100644 --- a/src/main/java/notai/document/presentation/DocumentController.java +++ b/src/main/java/notai/document/presentation/DocumentController.java @@ -36,7 +36,7 @@ public class DocumentController { @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity saveDocument( - @Auth Member member, + @Auth Long memberId, @PathVariable Long folderId, @Parameter(content = @Content(mediaType = MediaType.APPLICATION_PDF_VALUE)) @RequestPart MultipartFile pdfFile, @@ -45,9 +45,9 @@ public ResponseEntity saveDocument( DocumentSaveResult documentSaveResult; if (folderId.equals(ROOT_FOLDER_ID)) { - documentSaveResult = documentService.saveRootDocument(member, pdfFile, documentSaveRequest); + documentSaveResult = documentService.saveRootDocument(memberId, pdfFile, documentSaveRequest); } else { - documentSaveResult = documentService.saveDocument(member, folderId, pdfFile, documentSaveRequest); + documentSaveResult = documentService.saveDocument(memberId, folderId, pdfFile, documentSaveRequest); } DocumentSaveResponse response = DocumentSaveResponse.from(documentSaveResult); String url = String.format(FOLDER_URL_FORMAT, folderId, response.id()); @@ -56,12 +56,12 @@ public ResponseEntity saveDocument( @PutMapping(value = "/{id}") public ResponseEntity updateDocument( - @Auth Member member, + @Auth Long memberId, @PathVariable Long folderId, @PathVariable Long id, @RequestBody DocumentUpdateRequest documentUpdateRequest ) { - DocumentUpdateResult documentUpdateResult = documentService.updateDocument(member, + DocumentUpdateResult documentUpdateResult = documentService.updateDocument(memberId, folderId, id, documentUpdateRequest @@ -72,11 +72,11 @@ public ResponseEntity updateDocument( @GetMapping public ResponseEntity> getDocuments( - @Auth Member member, @PathVariable Long folderId + @Auth Long memberId, @PathVariable Long folderId ) { List documentResults; if (folderId.equals(ROOT_FOLDER_ID)) { - documentResults = documentQueryService.findRootDocuments(member.getId()); + documentResults = documentQueryService.findRootDocuments(memberId); } else { documentResults = documentQueryService.findDocuments(folderId); } @@ -87,9 +87,9 @@ public ResponseEntity> getDocuments( @DeleteMapping("/{id}") public ResponseEntity deleteDocument( - @Auth Member member, @PathVariable Long folderId, @PathVariable Long id + @Auth Long memberId, @PathVariable Long folderId, @PathVariable Long id ) { - documentService.deleteDocument(member, folderId, id); + documentService.deleteDocument(memberId, folderId, id); return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/notai/folder/application/FolderQueryService.java b/src/main/java/notai/folder/application/FolderQueryService.java index 0ee9c14..46acc4a 100644 --- a/src/main/java/notai/folder/application/FolderQueryService.java +++ b/src/main/java/notai/folder/application/FolderQueryService.java @@ -18,17 +18,17 @@ public class FolderQueryService { private final FolderRepository folderRepository; private static final Long ROOT_ID = -1L; - public List getFolders(Member member, Long folderId) { - List folders = getFoldersWithMemberAndParent(member, folderId); + public List getFolders(Long memberId, Long folderId) { + List folders = getFoldersWithMemberAndParent(memberId, folderId); // document read return folders.stream().map(this::getFolderResult).toList(); } - private List getFoldersWithMemberAndParent(Member member, Long folderId) { + private List getFoldersWithMemberAndParent(Long memberId, Long folderId) { if (folderId == null || folderId.equals(ROOT_ID)) { - return folderRepository.findAllByMemberIdAndParentFolderIsNull(member.getId()); + return folderRepository.findAllByMemberIdAndParentFolderIsNull(memberId); } - return folderRepository.findAllByMemberIdAndParentFolderId(member.getId(), folderId); + return folderRepository.findAllByMemberIdAndParentFolderId(memberId, folderId); } private FolderFindResult getFolderResult(Folder folder) { diff --git a/src/main/java/notai/folder/application/FolderService.java b/src/main/java/notai/folder/application/FolderService.java index 7fd965a..c7c9087 100644 --- a/src/main/java/notai/folder/application/FolderService.java +++ b/src/main/java/notai/folder/application/FolderService.java @@ -11,6 +11,7 @@ import notai.folder.presentation.request.FolderSaveRequest; import notai.folder.presentation.request.FolderUpdateRequest; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,53 +24,60 @@ public class FolderService { private final FolderRepository folderRepository; private final DocumentService documentService; + private final MemberRepository memberRepository; - public FolderSaveResult saveRootFolder(Member member, FolderSaveRequest folderSaveRequest) { + public FolderSaveResult saveRootFolder(Long memberId, FolderSaveRequest folderSaveRequest) { + Member member = memberRepository.getById(memberId); Folder folder = new Folder(member, folderSaveRequest.name()); Folder savedFolder = folderRepository.save(folder); return getFolderSaveResult(savedFolder); } - public FolderSaveResult saveSubFolder(Member member, FolderSaveRequest folderSaveRequest) { + public FolderSaveResult saveSubFolder(Long memberId, FolderSaveRequest folderSaveRequest) { Folder parentFolder = folderRepository.getById(folderSaveRequest.parentFolderId()); + Member member = memberRepository.getById(memberId); Folder folder = new Folder(member, folderSaveRequest.name(), parentFolder); Folder savedFolder = folderRepository.save(folder); return getFolderSaveResult(savedFolder); } - public FolderMoveResult moveRootFolder(Member member, Long id) { + public FolderMoveResult moveRootFolder(Long memberId, Long id) { Folder folder = folderRepository.getById(id); + Member member = memberRepository.getById(memberId); folder.validateOwner(member); folder.moveRootFolder(); folderRepository.save(folder); return getFolderMoveResult(folder); } - public FolderMoveResult moveNewParentFolder(Member member, Long id, FolderMoveRequest folderMoveRequest) { + public FolderMoveResult moveNewParentFolder(Long memberId, Long id, FolderMoveRequest folderMoveRequest) { Folder folder = folderRepository.getById(id); Folder parentFolder = folderRepository.getById(folderMoveRequest.targetFolderId()); + Member member = memberRepository.getById(memberId); folder.validateOwner(member); folder.moveNewParentFolder(parentFolder); folderRepository.save(folder); return getFolderMoveResult(folder); } - public FolderUpdateResult updateFolder(Member member, Long id, FolderUpdateRequest folderUpdateRequest) { + public FolderUpdateResult updateFolder(Long memberId, Long id, FolderUpdateRequest folderUpdateRequest) { Folder folder = folderRepository.getById(id); + Member member = memberRepository.getById(memberId); folder.validateOwner(member); folder.updateName(folderUpdateRequest.name()); folderRepository.save(folder); return getFolderUpdateResult(folder); } - public void deleteFolder(Member member, Long id) { + public void deleteFolder(Long memberId, Long id) { Folder folder = folderRepository.getById(id); + Member member = memberRepository.getById(memberId); folder.validateOwner(member); List subFolders = folderRepository.findAllByParentFolder(folder); for (Folder subFolder : subFolders) { - deleteFolder(member, subFolder.getId()); + deleteFolder(memberId, subFolder.getId()); } - documentService.deleteAllByFolder(member, folder); + documentService.deleteAllByFolder(memberId, folder); folderRepository.delete(folder); } diff --git a/src/main/java/notai/folder/presentation/FolderController.java b/src/main/java/notai/folder/presentation/FolderController.java index 748a807..1a8d540 100644 --- a/src/main/java/notai/folder/presentation/FolderController.java +++ b/src/main/java/notai/folder/presentation/FolderController.java @@ -16,7 +16,6 @@ import notai.folder.presentation.request.FolderSaveRequest; import notai.folder.presentation.request.FolderUpdateRequest; import notai.folder.presentation.response.*; -import notai.member.domain.Member; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -37,67 +36,67 @@ public class FolderController { @PostMapping public ResponseEntity saveFolder( - @Auth Member member, @Valid @RequestBody FolderSaveRequest folderSaveRequest + @Auth Long memberId, @Valid @RequestBody FolderSaveRequest folderSaveRequest ) { - FolderSaveResult folderResult = saveFolderResult(member, folderSaveRequest); + FolderSaveResult folderResult = saveFolderResult(memberId, folderSaveRequest); FolderSaveResponse response = FolderSaveResponse.from(folderResult); return ResponseEntity.created(URI.create("/api/folders/" + response.id())).body(response); } @PostMapping("/{id}/move") public ResponseEntity moveFolder( - @Auth Member member, @PathVariable Long id, @Valid @RequestBody FolderMoveRequest folderMoveRequest + @Auth Long memberId, @PathVariable Long id, @Valid @RequestBody FolderMoveRequest folderMoveRequest ) { - FolderMoveResult folderResult = moveFolderWithRequest(member, id, folderMoveRequest); + FolderMoveResult folderResult = moveFolderWithRequest(memberId, id, folderMoveRequest); FolderMoveResponse response = FolderMoveResponse.from(folderResult); return ResponseEntity.ok(response); } @PutMapping("/{id}") public ResponseEntity updateFolder( - @Auth Member member, @PathVariable Long id, @Valid @RequestBody FolderUpdateRequest folderUpdateRequest + @Auth Long memberId, @PathVariable Long id, @Valid @RequestBody FolderUpdateRequest folderUpdateRequest ) { - FolderUpdateResult folderResult = folderService.updateFolder(member, id, folderUpdateRequest); + FolderUpdateResult folderResult = folderService.updateFolder(memberId, id, folderUpdateRequest); FolderUpdateResponse response = FolderUpdateResponse.from(folderResult); return ResponseEntity.ok(response); } @GetMapping("/{id}") public ResponseEntity> getFolders( - @Auth Member member, @PathVariable Long id + @Auth Long memberId, @PathVariable Long id ) { List result = new ArrayList<>(); - insertFolderFindResponse(result, member, id); - insertDocumentFindResponse(result, member, id); + insertFolderFindResponse(result, memberId, id); + insertDocumentFindResponse(result, memberId, id); return ResponseEntity.ok(result); } @DeleteMapping("/{id}") public ResponseEntity deleteFolder( - @Auth Member member, @PathVariable Long id + @Auth Long memberId, @PathVariable Long id ) { - folderService.deleteFolder(member, id); + folderService.deleteFolder(memberId, id); return ResponseEntity.noContent().build(); } - private FolderSaveResult saveFolderResult(Member member, FolderSaveRequest folderSaveRequest) { + private FolderSaveResult saveFolderResult(Long memberId, FolderSaveRequest folderSaveRequest) { if (folderSaveRequest.parentFolderId() != null) { - return folderService.saveSubFolder(member, folderSaveRequest); + return folderService.saveSubFolder(memberId, folderSaveRequest); } - return folderService.saveRootFolder(member, folderSaveRequest); + return folderService.saveRootFolder(memberId, folderSaveRequest); } - private FolderMoveResult moveFolderWithRequest(Member member, Long id, FolderMoveRequest folderMoveRequest) { + private FolderMoveResult moveFolderWithRequest(Long memberId, Long id, FolderMoveRequest folderMoveRequest) { if (folderMoveRequest.targetFolderId() != null) { - return folderService.moveNewParentFolder(member, id, folderMoveRequest); + return folderService.moveNewParentFolder(memberId, id, folderMoveRequest); } - return folderService.moveRootFolder(member, id); + return folderService.moveRootFolder(memberId, id); } - private void insertFolderFindResponse(List result, Member member, Long folderId) { - List folderResults = folderQueryService.getFolders(member, folderId); + private void insertFolderFindResponse(List result, Long memberId, Long folderId) { + List folderResults = folderQueryService.getFolders(memberId, folderId); List folderResponses = folderResults.stream().map(FolderFindResponse::from).toList(); for (FolderFindResponse response : folderResponses) { @@ -105,10 +104,10 @@ private void insertFolderFindResponse(List result, Member m } } - private void insertDocumentFindResponse(List result, Member member, Long folderId) { + private void insertDocumentFindResponse(List result, Long memberId, Long folderId) { List documentResults; if (folderId == null || folderId.equals(ROOT_ID)) { - documentResults = documentQueryService.findRootDocuments(member.getId()); + documentResults = documentQueryService.findRootDocuments(memberId); } else { documentResults = documentQueryService.findDocuments(folderId); } diff --git a/src/main/java/notai/llm/application/LlmTaskQueryService.java b/src/main/java/notai/llm/application/LlmTaskQueryService.java index ec55477..d1c9aad 100644 --- a/src/main/java/notai/llm/application/LlmTaskQueryService.java +++ b/src/main/java/notai/llm/application/LlmTaskQueryService.java @@ -16,6 +16,7 @@ import notai.llm.domain.TaskStatus; import notai.llm.query.LlmTaskQueryRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.problem.domain.ProblemRepository; import notai.problem.query.result.ProblemPageContentResult; import notai.summary.domain.SummaryRepository; @@ -37,9 +38,11 @@ public class LlmTaskQueryService { private final DocumentRepository documentRepository; private final SummaryRepository summaryRepository; private final ProblemRepository problemRepository; + private final MemberRepository memberRepository; - public LlmTaskOverallStatusResult fetchOverallStatus(Member member, Long documentId) { + public LlmTaskOverallStatusResult fetchOverallStatus(Long memberId, Long documentId) { Document foundDocument = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); foundDocument.validateOwner(member); List summaryIds = summaryRepository.getSummaryIdsByDocumentId(documentId); @@ -59,8 +62,9 @@ public LlmTaskOverallStatusResult fetchOverallStatus(Member member, Long documen return LlmTaskOverallStatusResult.of(documentId, IN_PROGRESS, totalPages, completedPages); } - public LlmTaskPageStatusResult fetchPageStatus(Member member, LlmTaskPageStatusCommand command) { // TODO: 페이지 번호 검증 추가 + public LlmTaskPageStatusResult fetchPageStatus(Long memberId, LlmTaskPageStatusCommand command) { // TODO: 페이지 번호 검증 추가 Document foundDocument = documentRepository.getById(command.documentId()); + Member member = memberRepository.getById(memberId); foundDocument.validateOwner(member); Long summaryId = @@ -72,8 +76,9 @@ public LlmTaskPageStatusResult fetchPageStatus(Member member, LlmTaskPageStatusC return LlmTaskPageStatusResult.from(llmTaskQueryRepository.getTaskStatusBySummaryId(summaryId)); } - public LlmTaskAllPagesResult findAllPagesResult(Member member, Long documentId) { + public LlmTaskAllPagesResult findAllPagesResult(Long memberId, Long documentId) { Document foundDocument = documentRepository.getById(documentId); + Member member = memberRepository.getById(memberId); foundDocument.validateOwner(member); List summaryResults = @@ -98,8 +103,9 @@ public LlmTaskAllPagesResult findAllPagesResult(Member member, Long documentId) return LlmTaskAllPagesResult.of(documentId, results); } - public LlmTaskPageResult findPageResult(Member member, LlmTaskPageResultCommand command) { // TODO: 페이지 번호 검증 추가 + public LlmTaskPageResult findPageResult(Long memberId, LlmTaskPageResultCommand command) { // TODO: 페이지 번호 검증 추가 Document foundDocument = documentRepository.getById(command.documentId()); + Member member = memberRepository.getById(memberId); foundDocument.validateOwner(member); String summaryResult = summaryRepository.getSummaryContentByDocumentIdAndPageNumber( diff --git a/src/main/java/notai/llm/presentation/LlmTaskController.java b/src/main/java/notai/llm/presentation/LlmTaskController.java index e259d21..eed06e8 100644 --- a/src/main/java/notai/llm/presentation/LlmTaskController.java +++ b/src/main/java/notai/llm/presentation/LlmTaskController.java @@ -34,39 +34,39 @@ public ResponseEntity submitTask(@RequestBody @Valid LlmT @GetMapping("/status/{documentId}") public ResponseEntity fetchOverallStatus( - @Auth Member member, @PathVariable("documentId") Long documentId + @Auth Long memberId, @PathVariable("documentId") Long documentId ) { - LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member, documentId); + LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(memberId, documentId); return ResponseEntity.ok(LlmTaskOverallStatusResponse.from(result)); } @GetMapping("/status/{documentId}/{pageNumber}") public ResponseEntity fetchPageStatus( - @Auth Member member, + @Auth Long memberId, @PathVariable("documentId") Long documentId, @PathVariable("pageNumber") Integer pageNumber ) { LlmTaskPageStatusCommand command = LlmTaskPageStatusCommand.of(documentId, pageNumber); - LlmTaskPageStatusResult result = llmTaskQueryService.fetchPageStatus(member, command); + LlmTaskPageStatusResult result = llmTaskQueryService.fetchPageStatus(memberId, command); return ResponseEntity.ok(LlmTaskPageStatusResponse.from(result)); } @GetMapping("/results/{documentId}") public ResponseEntity findAllPagesResult( - @Auth Member member, @PathVariable("documentId") Long documentId + @Auth Long memberId, @PathVariable("documentId") Long documentId ) { - LlmTaskAllPagesResult result = llmTaskQueryService.findAllPagesResult(member, documentId); + LlmTaskAllPagesResult result = llmTaskQueryService.findAllPagesResult(memberId, documentId); return ResponseEntity.ok(LlmTaskAllPagesResultResponse.from(result)); } @GetMapping("/results/{documentId}/{pageNumber}") public ResponseEntity findPageResult( - @Auth Member member, + @Auth Long memberId, @PathVariable("documentId") Long documentId, @PathVariable("pageNumber") Integer pageNumber ) { LlmTaskPageResultCommand command = LlmTaskPageResultCommand.of(documentId, pageNumber); - LlmTaskPageResult result = llmTaskQueryService.findPageResult(member, command); + LlmTaskPageResult result = llmTaskQueryService.findPageResult(memberId, command); return ResponseEntity.ok(LlmTaskPageResultResponse.from(result)); } diff --git a/src/main/java/notai/member/presentation/MemberController.java b/src/main/java/notai/member/presentation/MemberController.java index 19c63cc..bc56652 100644 --- a/src/main/java/notai/member/presentation/MemberController.java +++ b/src/main/java/notai/member/presentation/MemberController.java @@ -48,8 +48,8 @@ public ResponseEntity refreshToken( @GetMapping("/me") public ResponseEntity findMyProfile( - @Auth Member member + @Auth Long memberId ) { - return ResponseEntity.ok(MemberFindResponse.from(member)); + return ResponseEntity.ok(MemberFindResponse.from(memberQueryService.findById(memberId))); } } diff --git a/src/main/java/notai/member/presentation/response/MemberFindResponse.java b/src/main/java/notai/member/presentation/response/MemberFindResponse.java index d64a550..ebd525b 100644 --- a/src/main/java/notai/member/presentation/response/MemberFindResponse.java +++ b/src/main/java/notai/member/presentation/response/MemberFindResponse.java @@ -1,12 +1,12 @@ package notai.member.presentation.response; -import notai.member.domain.Member; +import notai.member.application.result.MemberFindResult; public record MemberFindResponse( Long id, String nickname ) { - public static MemberFindResponse from(Member member) { - return new MemberFindResponse(member.getId(), member.getNickname()); + public static MemberFindResponse from(MemberFindResult result) { + return new MemberFindResponse(result.id(), result.nickname()); } } diff --git a/src/main/java/notai/ocr/application/OCRQueryService.java b/src/main/java/notai/ocr/application/OCRQueryService.java index 688c7ce..51ac0ba 100644 --- a/src/main/java/notai/ocr/application/OCRQueryService.java +++ b/src/main/java/notai/ocr/application/OCRQueryService.java @@ -4,6 +4,7 @@ import static notai.common.exception.ErrorMessages.OCR_RESULT_NOT_FOUND; import notai.common.exception.type.NotFoundException; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.ocr.application.result.OCRFindResult; import notai.ocr.domain.OCR; import notai.ocr.domain.OCRRepository; @@ -16,8 +17,11 @@ public class OCRQueryService { private final OCRRepository ocrRepository; + private final MemberRepository memberRepository; + + public OCRFindResult findOCR(Long memberId, Long documentId, Integer pageNumber) { + Member member = memberRepository.getById(memberId); - public OCRFindResult findOCR(Member member, Long documentId, Integer pageNumber) { OCR ocr = ocrRepository.findOCRByDocumentIdAndPageNumber( documentId, pageNumber diff --git a/src/main/java/notai/ocr/presentation/OCRController.java b/src/main/java/notai/ocr/presentation/OCRController.java index 06786b9..082271d 100644 --- a/src/main/java/notai/ocr/presentation/OCRController.java +++ b/src/main/java/notai/ocr/presentation/OCRController.java @@ -18,9 +18,9 @@ public class OCRController { @GetMapping public ResponseEntity getDocuments( - @Auth Member member, @PathVariable Long documentId, @RequestParam Integer pageNumber + @Auth Long memberId, @PathVariable Long documentId, @RequestParam Integer pageNumber ) { - OCRFindResult result = ocrQueryService.findOCR(member, documentId, pageNumber); + OCRFindResult result = ocrQueryService.findOCR(memberId, documentId, pageNumber); OCRFindResponse response = OCRFindResponse.from(result); return ResponseEntity.ok(response); } diff --git a/src/main/java/notai/pageRecording/application/PageRecordingService.java b/src/main/java/notai/pageRecording/application/PageRecordingService.java index a468a69..e296c77 100644 --- a/src/main/java/notai/pageRecording/application/PageRecordingService.java +++ b/src/main/java/notai/pageRecording/application/PageRecordingService.java @@ -4,6 +4,7 @@ import notai.document.domain.Document; import notai.document.domain.DocumentRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.pageRecording.application.command.PageRecordingSaveCommand; import notai.pageRecording.domain.PageRecording; import notai.pageRecording.domain.PageRecordingRepository; @@ -20,10 +21,13 @@ public class PageRecordingService { private final PageRecordingRepository pageRecordingRepository; private final RecordingRepository recordingRepository; private final DocumentRepository documentRepository; + private final MemberRepository memberRepository; - public void savePageRecording(Member member, PageRecordingSaveCommand command) { + public void savePageRecording(Long memberId, PageRecordingSaveCommand command) { Recording foundRecording = recordingRepository.getById(command.recordingId()); Document foundDocument = documentRepository.getById(command.documentId()); + Member member = memberRepository.getById(memberId); + foundDocument.validateOwner(member); foundRecording.validateDocumentOwnership(foundDocument); diff --git a/src/main/java/notai/pageRecording/presentation/PageRecordingController.java b/src/main/java/notai/pageRecording/presentation/PageRecordingController.java index 6bfeced..6c41f4a 100644 --- a/src/main/java/notai/pageRecording/presentation/PageRecordingController.java +++ b/src/main/java/notai/pageRecording/presentation/PageRecordingController.java @@ -20,12 +20,12 @@ public class PageRecordingController { @PostMapping public ResponseEntity savePageRecording( - @Auth Member member, + @Auth Long memberId, @PathVariable("documentId") Long documentId, @RequestBody PageRecordingSaveRequest request ) { PageRecordingSaveCommand command = request.toCommand(documentId); - pageRecordingService.savePageRecording(member, command); + pageRecordingService.savePageRecording(memberId, command); return ResponseEntity.status(CREATED).build(); } } diff --git a/src/main/java/notai/recording/application/RecordingService.java b/src/main/java/notai/recording/application/RecordingService.java index 0d87b96..4014fef 100644 --- a/src/main/java/notai/recording/application/RecordingService.java +++ b/src/main/java/notai/recording/application/RecordingService.java @@ -9,6 +9,7 @@ import notai.document.domain.Document; import notai.document.domain.DocumentRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.recording.application.command.RecordingSaveCommand; import notai.recording.application.result.RecordingSaveResult; import notai.recording.domain.Recording; @@ -36,12 +37,14 @@ public class RecordingService { private final AudioDecoder audioDecoder; private final FileManager fileManager; private final SttTaskService sttTaskService; + private final MemberRepository memberRepository; @Value("${file.audio.basePath}") private String audioBasePath; - public RecordingSaveResult saveRecording(Member member, RecordingSaveCommand command) { + public RecordingSaveResult saveRecording(Long memberId, RecordingSaveCommand command) { Document foundDocument = documentRepository.getById(command.documentId()); + Member member = memberRepository.getById(memberId); foundDocument.validateOwner(member); Recording recording = new Recording(foundDocument); diff --git a/src/main/java/notai/recording/presentation/RecordingController.java b/src/main/java/notai/recording/presentation/RecordingController.java index 4daf0dc..e470f12 100644 --- a/src/main/java/notai/recording/presentation/RecordingController.java +++ b/src/main/java/notai/recording/presentation/RecordingController.java @@ -23,12 +23,12 @@ public class RecordingController { @PostMapping public ResponseEntity saveRecording( - @Auth Member member, + @Auth Long memberId, @PathVariable("documentId") Long documentId, @RequestBody @Valid RecordingSaveRequest request ) { RecordingSaveCommand command = request.toCommand(documentId); - RecordingSaveResult result = recordingService.saveRecording(member, command); + RecordingSaveResult result = recordingService.saveRecording(memberId, command); return ResponseEntity.status(CREATED).body(RecordingSaveResponse.from(result)); } } diff --git a/src/test/java/notai/annotation/presentation/AnnotationControllerTest.java b/src/test/java/notai/annotation/presentation/AnnotationControllerTest.java index fcdf64a..230f738 100644 --- a/src/test/java/notai/annotation/presentation/AnnotationControllerTest.java +++ b/src/test/java/notai/annotation/presentation/AnnotationControllerTest.java @@ -66,7 +66,7 @@ void testCreateAnnotation_success() throws Exception { LocalDateTime now = LocalDateTime.now(); AnnotationResponse response = new AnnotationResponse(1L, 1L, 1, 100, 200, 300, 100, "굵은글씨", now.toString(), now.toString()); - when(annotationService.createAnnotation(any(Member.class), anyLong(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyString())) + when(annotationService.createAnnotation(any(Long.class), anyLong(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyString())) .thenReturn(response); mockMvc.perform(post("/api/documents/1/annotations") @@ -93,7 +93,7 @@ void testGetAnnotations_success() throws Exception { new AnnotationResponse(2L, 1L, 2, 150, 250, 350, 120, "", now.toString(), now.toString()) ); - when(annotationQueryService.getAnnotationsByDocumentAndPageNumbers(any(Member.class), anyLong(), anyList())).thenReturn(responses); + when(annotationQueryService.getAnnotationsByDocumentAndPageNumbers(any(Long.class), anyLong(), anyList())).thenReturn(responses); mockMvc.perform(get("/api/documents/1/annotations?pageNumbers=1,2") .contentType("application/json") @@ -122,7 +122,7 @@ void testUpdateAnnotation_success() throws Exception { LocalDateTime now = LocalDateTime.now(); AnnotationResponse response = new AnnotationResponse(1L, 1L, 1, 150, 250, 350, 120, "수정된 주석", now.toString(), now.toString()); - when(annotationService.updateAnnotation(any(Member.class), anyLong(), anyLong(), anyInt(), anyInt(), anyInt(), anyInt(), anyString())) + when(annotationService.updateAnnotation(any(Long.class), anyLong(), anyLong(), anyInt(), anyInt(), anyInt(), anyInt(), anyString())) .thenReturn(response); mockMvc.perform(put("/api/documents/1/annotations/1") @@ -142,13 +142,13 @@ void testUpdateAnnotation_success() throws Exception { @Test void testDeleteAnnotation_success() throws Exception { - doNothing().when(annotationService).deleteAnnotation(any(Member.class), anyLong(), anyLong()); + doNothing().when(annotationService).deleteAnnotation(any(Long.class), anyLong(), anyLong()); mockMvc.perform(delete("/api/documents/1/annotations/1") .contentType("application/json") .header("Authorization", "Bearer token")) .andExpect(status().isOk()); - verify(annotationService, times(1)).deleteAnnotation(any(Member.class),anyLong(), anyLong()); + verify(annotationService, times(1)).deleteAnnotation(any(Long.class),anyLong(), anyLong()); } } diff --git a/src/test/java/notai/folder/application/FolderQueryServiceTest.java b/src/test/java/notai/folder/application/FolderQueryServiceTest.java index 2071361..e879f8d 100644 --- a/src/test/java/notai/folder/application/FolderQueryServiceTest.java +++ b/src/test/java/notai/folder/application/FolderQueryServiceTest.java @@ -44,7 +44,7 @@ void getFolders_success_parentFolderIdIsNull() { when(folderRepository.findAllByMemberIdAndParentFolderIsNull(any(Long.class))).thenReturn(expectedResults); //when - List folders = folderQueryService.getFolders(member, null); + List folders = folderQueryService.getFolders(member.getId(), null); Assertions.assertThat(folders.size()).isEqualTo(1); } @@ -61,7 +61,7 @@ void getFolders_success_parentFolderId() { when(folderRepository.findAllByMemberIdAndParentFolderId(any(Long.class), any(Long.class))).thenReturn( expectedResults); //when - List folders = folderQueryService.getFolders(member, 1L); + List folders = folderQueryService.getFolders(member.getId(), 1L); Assertions.assertThat(folders.size()).isEqualTo(2); } diff --git a/src/test/java/notai/llm/application/LlmTaskQueryServiceTest.java b/src/test/java/notai/llm/application/LlmTaskQueryServiceTest.java index dd04d5b..92f5fc7 100644 --- a/src/test/java/notai/llm/application/LlmTaskQueryServiceTest.java +++ b/src/test/java/notai/llm/application/LlmTaskQueryServiceTest.java @@ -65,7 +65,7 @@ class LlmTaskQueryServiceTest { // when & then assertAll(() -> assertThrows( NotFoundException.class, - () -> llmTaskQueryService.fetchOverallStatus(member, 2L) + () -> llmTaskQueryService.fetchOverallStatus(member.getId(), 2L) )); } @@ -84,7 +84,7 @@ class LlmTaskQueryServiceTest { given(llmTaskQueryRepository.getTaskStatusBySummaryId(3L)).willReturn(COMPLETED); // when - LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member, documentId); + LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member.getId(), documentId); // then assertAll( @@ -111,7 +111,7 @@ class LlmTaskQueryServiceTest { given(llmTaskQueryRepository.getTaskStatusBySummaryId(3L)).willReturn(PENDING); // when - LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member, documentId); + LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member.getId(), documentId); // then assertAll( @@ -138,7 +138,7 @@ class LlmTaskQueryServiceTest { given(llmTaskQueryRepository.getTaskStatusBySummaryId(summaryId)).willReturn(IN_PROGRESS); // when - LlmTaskPageStatusResult result = llmTaskQueryService.fetchPageStatus(member, command); + LlmTaskPageStatusResult result = llmTaskQueryService.fetchPageStatus(member.getId(), command); // then assertThat(result.status()).isEqualTo(IN_PROGRESS); @@ -157,7 +157,7 @@ class LlmTaskQueryServiceTest { given(summaryRepository.getSummaryIdByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(null); // when - LlmTaskPageStatusResult result = llmTaskQueryService.fetchPageStatus(member, command); + LlmTaskPageStatusResult result = llmTaskQueryService.fetchPageStatus(member.getId(), command); // then assertThat(result.status()).isEqualTo(NOT_REQUESTED); @@ -171,7 +171,7 @@ class LlmTaskQueryServiceTest { // when & then assertAll(() -> assertThrows( NotFoundException.class, - () -> llmTaskQueryService.findAllPagesResult(member, 2L) + () -> llmTaskQueryService.findAllPagesResult(member.getId(), 2L) )); } @@ -195,7 +195,7 @@ class LlmTaskQueryServiceTest { assertAll( () -> assertThrows( InternalServerErrorException.class, - () -> llmTaskQueryService.findAllPagesResult(member, 1L) + () -> llmTaskQueryService.findAllPagesResult(member.getId(), 1L) ), () -> verify(summaryRepository).getPageNumbersAndContentByDocumentId(documentId), () -> verify(problemRepository).getPageNumbersAndContentByDocumentId(documentId) @@ -222,7 +222,7 @@ class LlmTaskQueryServiceTest { given(problemRepository.getPageNumbersAndContentByDocumentId(documentId)).willReturn(problemResults); // when - LlmTaskAllPagesResult response = llmTaskQueryService.findAllPagesResult(member, documentId); + LlmTaskAllPagesResult response = llmTaskQueryService.findAllPagesResult(member.getId(), documentId); // then assertAll( @@ -251,7 +251,7 @@ class LlmTaskQueryServiceTest { problemResult); // when - LlmTaskPageResult result = llmTaskQueryService.findPageResult(member, command); + LlmTaskPageResult result = llmTaskQueryService.findPageResult(member.getId(), command); // then assertAll( @@ -274,7 +274,7 @@ class LlmTaskQueryServiceTest { given(problemRepository.getProblemContentByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(null); // when - LlmTaskPageResult result = llmTaskQueryService.findPageResult(member, command); + LlmTaskPageResult result = llmTaskQueryService.findPageResult(member.getId(), command); // then assertAll( @@ -299,7 +299,7 @@ class LlmTaskQueryServiceTest { given(problemRepository.getProblemContentByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(null); // when & then - assertThrows(InternalServerErrorException.class, () -> llmTaskQueryService.findPageResult(member, command)); + assertThrows(InternalServerErrorException.class, () -> llmTaskQueryService.findPageResult(member.getId(), command)); } @Test @@ -313,7 +313,7 @@ class LlmTaskQueryServiceTest { willDoNothing().given(document).validateOwner(member); // when - LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member, documentId); + LlmTaskOverallStatusResult result = llmTaskQueryService.fetchOverallStatus(member.getId(), documentId); // then assertAll( @@ -334,7 +334,7 @@ class LlmTaskQueryServiceTest { willDoNothing().given(document).validateOwner(member); // when - LlmTaskAllPagesResult result = llmTaskQueryService.findAllPagesResult(member, documentId); + LlmTaskAllPagesResult result = llmTaskQueryService.findAllPagesResult(member.getId(), documentId); // then assertAll( diff --git a/src/test/java/notai/pageRecording/application/PageRecordingServiceTest.java b/src/test/java/notai/pageRecording/application/PageRecordingServiceTest.java index a57ec5f..7ce0586 100644 --- a/src/test/java/notai/pageRecording/application/PageRecordingServiceTest.java +++ b/src/test/java/notai/pageRecording/application/PageRecordingServiceTest.java @@ -3,6 +3,7 @@ import notai.document.domain.Document; import notai.document.domain.DocumentRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.pageRecording.application.command.PageRecordingSaveCommand; import notai.pageRecording.application.command.PageRecordingSaveCommand.PageRecordingSession; import notai.pageRecording.domain.PageRecording; @@ -34,6 +35,9 @@ class PageRecordingServiceTest { @Mock private DocumentRepository documentRepository; + @Mock + private MemberRepository memberRepository; + @Mock private Member member; @@ -54,13 +58,13 @@ class PageRecordingServiceTest { Recording foundRecording = mock(Recording.class); given(recordingRepository.getById(recordingId)).willReturn(foundRecording); - + given(memberRepository.getById(anyLong())).willReturn(member); given(documentRepository.getById(anyLong())).willReturn(document); willDoNothing().given(document).validateOwner(member); willDoNothing().given(foundRecording).validateDocumentOwnership(any(Document.class)); // when - pageRecordingService.savePageRecording(member, command); + pageRecordingService.savePageRecording(member.getId(), command); // then verify(pageRecordingRepository, times(2)).save(any(PageRecording.class)); diff --git a/src/test/java/notai/recording/application/RecordingServiceTest.java b/src/test/java/notai/recording/application/RecordingServiceTest.java index d0545ad..59cc532 100644 --- a/src/test/java/notai/recording/application/RecordingServiceTest.java +++ b/src/test/java/notai/recording/application/RecordingServiceTest.java @@ -7,6 +7,7 @@ import notai.document.domain.Document; import notai.document.domain.DocumentRepository; import notai.member.domain.Member; +import notai.member.domain.MemberRepository; import notai.recording.application.command.RecordingSaveCommand; import notai.recording.application.result.RecordingSaveResult; import notai.recording.domain.Recording; @@ -47,6 +48,9 @@ class RecordingServiceTest { @Mock private SttTaskService sttTaskService; + @Mock + private MemberRepository memberRepository; + @Spy private final AudioDecoder audioDecoder = new AudioDecoder(); @@ -75,11 +79,12 @@ void setUp() { given(documentRepository.getById(anyLong())).willReturn(document); given(recordingRepository.save(any(Recording.class))).willReturn(savedRecording); + given(memberRepository.getById(anyLong())).willReturn(member); given(document.getName()).willReturn("안녕하세요백종원입니다"); // when & then assertThrows(BadRequestException.class, () -> { - recordingService.saveRecording(member, command); + recordingService.saveRecording(member.getId(), command); }); } @@ -98,12 +103,13 @@ void setUp() { given(documentRepository.getById(anyLong())).willReturn(document); given(recordingRepository.save(any(Recording.class))).willReturn(savedRecording); + given(memberRepository.getById(anyLong())).willReturn(member); given(document.getName()).willReturn("안녕하세요백종원입니다"); willDoNothing().given(sttTaskService).submitSttTask(any()); // when - RecordingSaveResult result = recordingService.saveRecording(member, command); + RecordingSaveResult result = recordingService.saveRecording(member.getId(), command); // then FilePath filePath = FilePath.from("안녕하세요백종원입니다_1.mp3"); @@ -111,4 +117,4 @@ void setUp() { assertAll(() -> assertTrue(Files.exists(expectedFilePath)), () -> assertTrue(Files.size(expectedFilePath) > 0)); } -} \ No newline at end of file +}