Skip to content

Commit

Permalink
Merge branch 'Weekly11' into release/0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
yugyeom-ghim committed Nov 11, 2024
2 parents aa30af5 + 682e28f commit 0a35e22
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/java/notai/auth/AuthArgumentResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public boolean supportsParameter(MethodParameter parameter) {
}

@Override
public Long resolveArgument(
public Member resolveArgument(
MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory
) {
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
Long memberId = (Long) request.getAttribute("memberId");
return memberRepository.getById(memberId).getId();
return memberRepository.getById(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,8 +22,8 @@ public List<DocumentFindResult> findDocuments(Long folderId) {
return documents.stream().map(this::getDocumentFindResult).toList();
}

public List<DocumentFindResult> findRootDocuments(Long memberId) {
List<Document> documents = documentRepository.findAllByMemberIdAndFolderIdIsNull(memberId);
public List<DocumentFindResult> findRootDocuments(Member member) {
List<Document> documents = documentRepository.findAllByMemberIdAndFolderIdIsNull(member.getId());
return documents.stream().map(this::getDocumentFindResult).toList();
}

Expand Down
26 changes: 10 additions & 16 deletions src/main/java/notai/document/application/DocumentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -83,18 +79,17 @@ public void deleteDocument(
}

public void deleteAllByFolder(
Long memberId, Folder folder
Member member, Folder folder
) {
List<Document> 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,
Expand All @@ -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(),
Expand Down

0 comments on commit 0a35e22

Please sign in to comment.