diff --git a/src/main/java/notai/auth/AuthArgumentResolver.java b/src/main/java/notai/auth/AuthArgumentResolver.java index d832eba..c81cb96 100644 --- a/src/main/java/notai/auth/AuthArgumentResolver.java +++ b/src/main/java/notai/auth/AuthArgumentResolver.java @@ -25,7 +25,7 @@ public boolean supportsParameter(MethodParameter parameter) { } @Override - public Long resolveArgument( + public Member resolveArgument( MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @@ -33,6 +33,6 @@ public Long resolveArgument( ) { HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); Long memberId = (Long) request.getAttribute("memberId"); - return memberRepository.getById(memberId).getId(); + return memberRepository.getById(memberId); } } diff --git a/src/main/java/notai/document/application/DocumentQueryService.java b/src/main/java/notai/document/application/DocumentQueryService.java index 6cbb050..ed0c11d 100644 --- a/src/main/java/notai/document/application/DocumentQueryService.java +++ b/src/main/java/notai/document/application/DocumentQueryService.java @@ -4,6 +4,7 @@ import notai.document.application.result.DocumentFindResult; import notai.document.domain.Document; import notai.document.domain.DocumentRepository; +import notai.member.domain.Member; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,8 +22,8 @@ public List findDocuments(Long folderId) { return documents.stream().map(this::getDocumentFindResult).toList(); } - public List findRootDocuments(Long memberId) { - List documents = documentRepository.findAllByMemberIdAndFolderIdIsNull(memberId); + public List findRootDocuments(Member member) { + List documents = documentRepository.findAllByMemberIdAndFolderIdIsNull(member.getId()); return documents.stream().map(this::getDocumentFindResult).toList(); } diff --git a/src/main/java/notai/document/application/DocumentService.java b/src/main/java/notai/document/application/DocumentService.java index 028e750..801c6cf 100644 --- a/src/main/java/notai/document/application/DocumentService.java +++ b/src/main/java/notai/document/application/DocumentService.java @@ -10,7 +10,6 @@ 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; @@ -29,33 +28,31 @@ 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( - Long memberId, Long folderId, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest + Member member, Long folderId, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest ) { PdfSaveResult pdfSaveResult = pdfService.savePdf(pdfFile); - Document document = saveAndReturnDocument(memberId, folderId, documentSaveRequest, pdfSaveResult); + Document document = saveAndReturnDocument(member, folderId, documentSaveRequest, pdfSaveResult); ocrService.saveOCR(document, pdfSaveResult.pdf()); return DocumentSaveResult.of(document.getId(), document.getName(), document.getUrl()); } public DocumentSaveResult saveRootDocument( - Long memberId, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest + Member member, MultipartFile pdfFile, DocumentSaveRequest documentSaveRequest ) { PdfSaveResult pdfSaveResult = pdfService.savePdf(pdfFile); - Document document = saveAndReturnRootDocument(memberId, documentSaveRequest, pdfSaveResult); + Document document = saveAndReturnRootDocument(member, documentSaveRequest, pdfSaveResult); ocrService.saveOCR(document, pdfSaveResult.pdf()); return DocumentSaveResult.of(document.getId(), document.getName(), document.getUrl()); } public DocumentUpdateResult updateDocument( - Long memberId, Long folderId, Long documentId, DocumentUpdateRequest documentUpdateRequest + Member member, Long folderId, Long documentId, DocumentUpdateRequest documentUpdateRequest ) { Document document = documentRepository.getById(documentId); - Member member = memberRepository.getById(memberId); document.validateOwner(member); @@ -68,10 +65,9 @@ public DocumentUpdateResult updateDocument( } public void deleteDocument( - Long memberId, Long folderId, Long documentId + Member member, Long folderId, Long documentId ) { Document document = documentRepository.getById(documentId); - Member member = memberRepository.getById(memberId); document.validateOwner(member); @@ -83,18 +79,17 @@ public void deleteDocument( } public void deleteAllByFolder( - Long memberId, Folder folder + Member member, Folder folder ) { List documents = documentRepository.findAllByFolderId(folder.getId()); for (Document document : documents) { - deleteDocument(memberId, folder.getId(), document.getId()); + deleteDocument(member, folder.getId(), document.getId()); } } private Document saveAndReturnDocument( - Long memberId, Long folderId, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult + Member member, Long folderId, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult ) { - Member member = memberRepository.getById(memberId); Folder folder = folderRepository.getById(folderId); Document document = new Document(folder, member, @@ -106,9 +101,8 @@ private Document saveAndReturnDocument( } private Document saveAndReturnRootDocument( - Long memberId, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult + Member member, DocumentSaveRequest documentSaveRequest, PdfSaveResult pdfSaveResult ) { - Member member = memberRepository.getById(memberId); Document document = new Document(member, documentSaveRequest.name(), pdfSaveResult.pdfUrl(),