refactor(documents): extract applyBatchMetadata private helper in DocumentService
storeDocumentWithBatchMetadata was a 30-line flat method mixing file storage with metadata hydration. The private helper makes each concern visible at a glance. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -146,8 +146,11 @@ public class DocumentService {
|
|||||||
public StoreResult storeDocumentWithBatchMetadata(
|
public StoreResult storeDocumentWithBatchMetadata(
|
||||||
MultipartFile file, DocumentBatchMetadataDTO metadata, int fileIndex, UUID actorId) throws IOException {
|
MultipartFile file, DocumentBatchMetadataDTO metadata, int fileIndex, UUID actorId) throws IOException {
|
||||||
StoreResult base = storeDocument(file, actorId);
|
StoreResult base = storeDocument(file, actorId);
|
||||||
Document doc = base.document();
|
Document doc = applyBatchMetadata(base.document(), metadata, fileIndex);
|
||||||
|
return new StoreResult(documentRepository.save(doc), base.isNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document applyBatchMetadata(Document doc, DocumentBatchMetadataDTO metadata, int fileIndex) {
|
||||||
if (metadata.getTitles() != null && fileIndex < metadata.getTitles().size()) {
|
if (metadata.getTitles() != null && fileIndex < metadata.getTitles().size()) {
|
||||||
doc.setTitle(metadata.getTitles().get(fileIndex));
|
doc.setTitle(metadata.getTitles().get(fileIndex));
|
||||||
}
|
}
|
||||||
@@ -172,9 +175,7 @@ public class DocumentService {
|
|||||||
doc = documentRepository.findById(docId)
|
doc = documentRepository.findById(docId)
|
||||||
.orElseThrow(() -> DomainException.notFound(ErrorCode.DOCUMENT_NOT_FOUND, "Not found after batch metadata: " + docId));
|
.orElseThrow(() -> DomainException.notFound(ErrorCode.DOCUMENT_NOT_FOUND, "Not found after batch metadata: " + docId));
|
||||||
}
|
}
|
||||||
|
return doc;
|
||||||
Document saved = documentRepository.save(doc);
|
|
||||||
return new StoreResult(saved, base.isNew());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
Reference in New Issue
Block a user