Skip to content

Commit

Permalink
[REFACTOR] 문서 null 체크 로직 adapter로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
Chan531 committed Aug 20, 2024
1 parent eb6e909 commit 3b16ce9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.tiki.server.document.adapter;

import static com.tiki.server.document.message.ErrorCode.INVALID_DOCUMENT;

import java.util.List;
import java.util.Objects;

import com.tiki.server.common.entity.Position;
import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.document.entity.Document;
import com.tiki.server.document.exception.DocumentException;
import com.tiki.server.document.repository.DocumentRepository;
import com.tiki.server.document.vo.DocumentVO;

Expand All @@ -17,7 +21,11 @@ public class DocumentFinder {
private final DocumentRepository documentRepository;

public Document findByIdWithTimeBlock(long documentId) {
return documentRepository.findByIdWithTimeBlock(documentId);
Document document = documentRepository.findByIdWithTimeBlock(documentId);
if (Objects.isNull(document)) {
throw new DocumentException(INVALID_DOCUMENT);
}
return document;
}

public List<DocumentVO> findAllByTimeBlockId(long timeBlockId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public DocumentsGetResponse getAllDocuments(long memberId, long teamId, String t
public void deleteDocument(long memberId, long teamId, long documentId) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Document document = documentFinder.findByIdWithTimeBlock(documentId);
checkDocumentExist(document);
memberTeamManager.checkMemberAccessible(document.getTimeBlock().getAccessiblePosition());
documentDeleter.delete(document);
}
Expand All @@ -48,10 +47,4 @@ private DocumentsGetResponse getAllDocumentsByType(long teamId, Position accessi
List<Document> documents = documentFinder.findAllByTeamIdAndAccessiblePosition(teamId, accessiblePosition);
return DocumentsGetResponse.from(documents);
}

private void checkDocumentExist(Document document) {
if (Objects.isNull(document)) {
throw new DocumentException(INVALID_DOCUMENT);
}
}
}

0 comments on commit 3b16ce9

Please sign in to comment.