Fix read status filter showing only “Unknown” with no results

This commit is contained in:
aditya.chandel
2025-07-10 09:43:36 -06:00
committed by Aditya Chandel
parent 538854b397
commit 480eb92f7d
6 changed files with 54 additions and 23 deletions
@@ -58,23 +58,31 @@ public class BookService {
public List<Book> getBookDTOs(boolean includeDescription) {
BookLoreUser user = authenticationService.getAuthenticatedUser();
boolean isAdmin = user.getPermissions().isAdmin();
List<Book> books;
if (isAdmin) {
books = bookQueryService.getAllBooks(includeDescription);
} else {
Set<Long> libraryIds = user.getAssignedLibraries().stream()
.map(Library::getId)
.collect(Collectors.toSet());
books = bookQueryService.getAllBooksByLibraryIds(libraryIds, includeDescription);
}
Map<Long, UserBookProgressEntity> progressMap = userProgressService.fetchUserProgress(user.getId(), books.stream().map(Book::getId).collect(Collectors.toSet()));
List<Book> books = isAdmin
? bookQueryService.getAllBooks(includeDescription)
: bookQueryService.getAllBooksByLibraryIds(
user.getAssignedLibraries().stream()
.map(Library::getId)
.collect(Collectors.toSet()),
includeDescription
);
Map<Long, UserBookProgressEntity> progressMap =
userProgressService.fetchUserProgress(
user.getId(),
books.stream().map(Book::getId).collect(Collectors.toSet())
);
books.forEach(book -> {
UserBookProgressEntity progress = progressMap.get(book.getId());
if (progress != null) {
setBookProgress(book, progress);
book.setLastReadTime(progress.getLastReadTime());
book.setReadStatus(String.valueOf(progress.getReadStatus()));
}
});
return books;
}