fix(backend): Fix metadata fields being stripped from API response, causing issues with filtering. (#250)

* chore(release): 2.3.0 [skip ci]

## [2.3.0](https://github.com/grimmory-tools/grimmory/compare/v2.2.6...v2.3.0) (2026-03-21)

### Features

* **release:** document develop-based stable release previews ([930e526](https://github.com/grimmory-tools/grimmory/commit/930e5262285540b3b65b9ef4f7be328a05dfb5b4))

### Bug Fixes

* **api:** fix potential memory leaks in file processing ([031e8ae](https://github.com/grimmory-tools/grimmory/commit/031e8ae257c3354cacce2d17c8c6bc35ce80badb))
* **ci:** correct artifact download action pin ([37ca101](https://github.com/grimmory-tools/grimmory/commit/37ca101dd4bd08ccfe6d4d2395ecc71298cc323d))
* **ci:** publish PR test results from workflow_run ([11a76bf](https://github.com/grimmory-tools/grimmory/commit/11a76bffe12f80d0271e3626291cfbd275346727))
* **ci:** repair release preview and test result publishing ([afa5b81](https://github.com/grimmory-tools/grimmory/commit/afa5b818ebe612e66acc819aa398ac0c6184d21b))
* drop telemetry from app ([#52](https://github.com/grimmory-tools/grimmory/issues/52)) ([4d82cb7](https://github.com/grimmory-tools/grimmory/commit/4d82cb718833a2a4e08ee2f18b2ff3ab9b043dd6))
* **ui:** repair frontend compile after rebrand ([fea1ec6](https://github.com/grimmory-tools/grimmory/commit/fea1ec6930ae64445c6d7e7b38bdc4e7925b51c1))

### Refactors

* **build:** rename frontend dist output to grimmory ([ecf388f](https://github.com/grimmory-tools/grimmory/commit/ecf388f7a2086fbd1d8737a972926d70ec3190d4))
* **i18n:** rename booklore translation keys to grimmory ([eb94afa](https://github.com/grimmory-tools/grimmory/commit/eb94afa7ad600eaa2535802583f21937bd1ae2c0))
* **metadata:** move default parser from Amazon to Goodreads ([e252122](https://github.com/grimmory-tools/grimmory/commit/e252122bc5a89c75af85ddbaae66a14d368479f9))
* pull kepubify & ffprobe during build ([#50](https://github.com/grimmory-tools/grimmory/issues/50)) ([1c15629](https://github.com/grimmory-tools/grimmory/commit/1c15629a10ba2e2ad78455f118e8c937b585b157))
* **ui:** rebrand frontend surfaces to grimmory ([d786dd8](https://github.com/grimmory-tools/grimmory/commit/d786dd8ccbebaa360385dce834816bcb6aaf3b2f))

### Chores

* **api:** remove the custom startup banner ([98c9b1a](https://github.com/grimmory-tools/grimmory/commit/98c9b1ae653c2140b7b2ab86b5511be3376bfe43))
* **deps:** bump flatted from 3.4.1 to 3.4.2 in /booklore-ui ([#73](https://github.com/grimmory-tools/grimmory/issues/73)) ([c4bd0c7](https://github.com/grimmory-tools/grimmory/commit/c4bd0c779ae398968dbdea6d566693ed57eab3eb))
* **funding:** point support links at opencollective ([55c0ac0](https://github.com/grimmory-tools/grimmory/commit/55c0ac089966b8586e7d7bdef1fc469049903d08))
* **release:** 2.2.7 [skip ci] ([0b5e24c](https://github.com/grimmory-tools/grimmory/commit/0b5e24c23848c9e97b04f4221303d0b4bf0b2dd7))
* remove old verbose PR template, replace with temporary more low-key one. ([#84](https://github.com/grimmory-tools/grimmory/issues/84)) ([b868526](https://github.com/grimmory-tools/grimmory/commit/b8685268a9a9730416a209201a70c284cee590c5))
* **ui:** drop financial support dialog ([#21](https://github.com/grimmory-tools/grimmory/issues/21)) ([62be6b1](https://github.com/grimmory-tools/grimmory/commit/62be6b152cbd42910620fdeae1f35783ea258b27))

### Documentation

* updated supported file formats in README.md ([#68](https://github.com/grimmory-tools/grimmory/issues/68)) ([f912e80](https://github.com/grimmory-tools/grimmory/commit/f912e802f97263206308817acd5bab84a5321dcf))

### Style

* **i18n:** normalize translation json formatting ([#89](https://github.com/grimmory-tools/grimmory/issues/89)) ([857290d](https://github.com/grimmory-tools/grimmory/commit/857290d215b518e61c9b3a058ae5d40d5e214672))
* **ui:** simplify the topbar logo branding ([0416d48](https://github.com/grimmory-tools/grimmory/commit/0416d48a6c441792b4c9607b3e472159c879d439))

* Fix backend from stripping fields

* Strip metadata fields by default in backend

* Fix merge conflicts

* Revert yarn.lock change

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Jin
2026-04-22 17:26:55 -04:00
committed by Zach Yale
co-authored by github-actions[bot]
parent 3f8a1852a6
commit c1711dd0c1
5 changed files with 15 additions and 12 deletions
@@ -68,8 +68,10 @@ public class BookController {
@GetMapping
public ResponseEntity<List<Book>> getBooks(
@Parameter(description = "Include book descriptions in the response")
@RequestParam(required = false, defaultValue = "false") boolean withDescription) {
return ResponseEntity.ok(bookService.getBookDTOs(withDescription));
@RequestParam(required = false, defaultValue = "false") boolean withDescription,
@Parameter(description = "Remove other metadata fields from the response")
@RequestParam(required = false, defaultValue = "true") boolean stripForListView) {
return ResponseEntity.ok(bookService.getBookDTOs(withDescription, stripForListView));
}
@Operation(summary = "Get a book by ID", description = "Retrieve details of a specific book by its ID.")
@@ -24,15 +24,15 @@ public class BookQueryService {
private final BookMapperV2 bookMapperV2;
private final ContentRestrictionService contentRestrictionService;
public List<Book> getAllBooks(boolean includeDescription) {
public List<Book> getAllBooks(boolean includeDescription, boolean stripForListView) {
List<BookEntity> books = bookRepository.findAllWithMetadata();
return mapBooksToDto(books, includeDescription, null, !includeDescription);
return mapBooksToDto(books, includeDescription, null, stripForListView);
}
public List<Book> getAllBooksByLibraryIds(Set<Long> libraryIds, boolean includeDescription, Long userId) {
public List<Book> getAllBooksByLibraryIds(Set<Long> libraryIds, boolean includeDescription, boolean StripForListView, Long userId) {
List<BookEntity> books = bookRepository.findAllWithMetadataByLibraryIds(libraryIds);
books = contentRestrictionService.applyRestrictions(books, userId);
return mapBooksToDto(books, includeDescription, userId, !includeDescription);
return mapBooksToDto(books, includeDescription, userId, StripForListView);
}
public List<BookEntity> findAllWithMetadataByIds(Set<Long> bookIds) {
@@ -72,15 +72,16 @@ public class BookService {
@Transactional(readOnly = true)
public List<Book> getBookDTOs(boolean includeDescription) {
public List<Book> getBookDTOs(boolean includeDescription, boolean stripForListView) {
BookLoreUser user = authenticationService.getAuthenticatedUser();
boolean isAdmin = user.getPermissions().isAdmin();
List<Book> books = isAdmin
? bookQueryService.getAllBooks(includeDescription)
? bookQueryService.getAllBooks(includeDescription, stripForListView)
: bookQueryService.getAllBooksByLibraryIds(
getUserLibraryIds(user),
includeDescription,
stripForListView,
user.getId()
);
@@ -101,14 +101,14 @@ class BookServiceTest {
@Test
void getBookDTOs_adminUser_returnsBooksWithProgress() {
Book book = Book.builder().id(1L).primaryFile(BookFile.builder().bookType(BookFileType.PDF).build()).shelves(Set.of()).build();
when(bookQueryService.getAllBooks(anyBoolean())).thenReturn(List.of(book));
when(bookQueryService.getAllBooks(anyBoolean(), anyBoolean())).thenReturn(List.of(book));
when(readingProgressService.fetchUserProgress(anyLong(), anySet())).thenReturn(Map.of(1L, new UserBookProgressEntity()));
when(authenticationService.getAuthenticatedUser()).thenReturn(testUser);
List<Book> result = bookService.getBookDTOs(true);
List<Book> result = bookService.getBookDTOs(true, false);
assertEquals(1, result.size());
verify(bookQueryService).getAllBooks(true);
verify(bookQueryService).getAllBooks(true, false);
}
@Test
@@ -101,7 +101,7 @@ export class BookService {
private getBooksQueryOptions() {
return queryOptions({
queryKey: BOOKS_QUERY_KEY,
queryFn: () => lastValueFrom(this.http.get<Book[]>(this.url))
queryFn: () => lastValueFrom(this.http.get<Book[]>(this.url, {params: {stripForListView: false}}))
});
}