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) {
Set<String> currentFileNames = libraryFiles.stream()
.map(LibraryFile::getFileName)
Set<Path> currentFullPaths = libraryFiles.stream()
.map(LibraryFile::getFullPath)
.collect(Collectors.toSet());
return libraryEntity.getBookEntities().stream()
.filter(book -> (book.getDeleted() == null || !book.getDeleted()))
.filter(book -> !currentFileNames.contains(book.getFileName()))
.filter(book -> !currentFullPaths.contains(book.getFullFilePath()))
.map(BookEntity::getId)
.collect(Collectors.toList());
}
public static List<LibraryFile> detectNewBookPaths(List<LibraryFile> libraryFiles, LibraryEntity libraryEntity) {
Set<String> existingFileNames = libraryEntity.getBookEntities().stream()
.map(BookEntity::getFileName)
Set<Path> existingFullPaths = libraryEntity.getBookEntities().stream()
.map(BookEntity::getFullFilePath)
.collect(Collectors.toSet());
return libraryFiles.stream()
.filter(file -> !existingFileNames.contains(file.getFileName()))
.filter(file -> !existingFullPaths.contains(file.getFullPath()))
.collect(Collectors.toList());
}