refactor(service): use full path instead of just name to sync book files

This commit is contained in:
Alexander Puzynia
2025-07-23 14:11:27 -06:00
committed by Aditya Chandel
parent c9e05b1c28
commit b7a17e1405
@@ -62,23 +62,23 @@ public class LibraryProcessingService {
} }
public static List<Long> detectDeletedBookIds(List<LibraryFile> libraryFiles, LibraryEntity libraryEntity) { public static List<Long> detectDeletedBookIds(List<LibraryFile> libraryFiles, LibraryEntity libraryEntity) {
Set<String> currentFileNames = libraryFiles.stream() Set<Path> currentFullPaths = libraryFiles.stream()
.map(LibraryFile::getFileName) .map(LibraryFile::getFullPath)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return libraryEntity.getBookEntities().stream() return libraryEntity.getBookEntities().stream()
.filter(book -> (book.getDeleted() == null || !book.getDeleted())) .filter(book -> (book.getDeleted() == null || !book.getDeleted()))
.filter(book -> !currentFileNames.contains(book.getFileName())) .filter(book -> !currentFullPaths.contains(book.getFullFilePath()))
.map(BookEntity::getId) .map(BookEntity::getId)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static List<LibraryFile> detectNewBookPaths(List<LibraryFile> libraryFiles, LibraryEntity libraryEntity) { public static List<LibraryFile> detectNewBookPaths(List<LibraryFile> libraryFiles, LibraryEntity libraryEntity) {
Set<String> existingFileNames = libraryEntity.getBookEntities().stream() Set<Path> existingFullPaths = libraryEntity.getBookEntities().stream()
.map(BookEntity::getFileName) .map(BookEntity::getFullFilePath)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return libraryFiles.stream() return libraryFiles.stream()
.filter(file -> !existingFileNames.contains(file.getFileName())) .filter(file -> !existingFullPaths.contains(file.getFullPath()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }