diff --git a/booklore-api/src/main/java/org/booklore/controller/BookController.java b/booklore-api/src/main/java/org/booklore/controller/BookController.java index cdc08ebcc..d9bf2d94b 100644 --- a/booklore-api/src/main/java/org/booklore/controller/BookController.java +++ b/booklore-api/src/main/java/org/booklore/controller/BookController.java @@ -68,8 +68,10 @@ public class BookController { @GetMapping public ResponseEntity> 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.") diff --git a/booklore-api/src/main/java/org/booklore/service/book/BookQueryService.java b/booklore-api/src/main/java/org/booklore/service/book/BookQueryService.java index 5273d3cd1..6b7510e36 100644 --- a/booklore-api/src/main/java/org/booklore/service/book/BookQueryService.java +++ b/booklore-api/src/main/java/org/booklore/service/book/BookQueryService.java @@ -24,15 +24,15 @@ public class BookQueryService { private final BookMapperV2 bookMapperV2; private final ContentRestrictionService contentRestrictionService; - public List getAllBooks(boolean includeDescription) { + public List getAllBooks(boolean includeDescription, boolean stripForListView) { List books = bookRepository.findAllWithMetadata(); - return mapBooksToDto(books, includeDescription, null, !includeDescription); + return mapBooksToDto(books, includeDescription, null, stripForListView); } - public List getAllBooksByLibraryIds(Set libraryIds, boolean includeDescription, Long userId) { + public List getAllBooksByLibraryIds(Set libraryIds, boolean includeDescription, boolean StripForListView, Long userId) { List books = bookRepository.findAllWithMetadataByLibraryIds(libraryIds); books = contentRestrictionService.applyRestrictions(books, userId); - return mapBooksToDto(books, includeDescription, userId, !includeDescription); + return mapBooksToDto(books, includeDescription, userId, StripForListView); } public List findAllWithMetadataByIds(Set bookIds) { diff --git a/booklore-api/src/main/java/org/booklore/service/book/BookService.java b/booklore-api/src/main/java/org/booklore/service/book/BookService.java index 8124fc471..5506a812e 100644 --- a/booklore-api/src/main/java/org/booklore/service/book/BookService.java +++ b/booklore-api/src/main/java/org/booklore/service/book/BookService.java @@ -72,15 +72,16 @@ public class BookService { @Transactional(readOnly = true) - public List getBookDTOs(boolean includeDescription) { + public List getBookDTOs(boolean includeDescription, boolean stripForListView) { BookLoreUser user = authenticationService.getAuthenticatedUser(); boolean isAdmin = user.getPermissions().isAdmin(); List books = isAdmin - ? bookQueryService.getAllBooks(includeDescription) + ? bookQueryService.getAllBooks(includeDescription, stripForListView) : bookQueryService.getAllBooksByLibraryIds( getUserLibraryIds(user), includeDescription, + stripForListView, user.getId() ); diff --git a/booklore-api/src/test/java/org/booklore/service/book/BookServiceTest.java b/booklore-api/src/test/java/org/booklore/service/book/BookServiceTest.java index 408ba6116..61add406c 100644 --- a/booklore-api/src/test/java/org/booklore/service/book/BookServiceTest.java +++ b/booklore-api/src/test/java/org/booklore/service/book/BookServiceTest.java @@ -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 result = bookService.getBookDTOs(true); + List result = bookService.getBookDTOs(true, false); assertEquals(1, result.size()); - verify(bookQueryService).getAllBooks(true); + verify(bookQueryService).getAllBooks(true, false); } @Test diff --git a/frontend/src/app/features/book/service/book.service.ts b/frontend/src/app/features/book/service/book.service.ts index cb1974cc9..55c0a9c44 100644 --- a/frontend/src/app/features/book/service/book.service.ts +++ b/frontend/src/app/features/book/service/book.service.ts @@ -101,7 +101,7 @@ export class BookService { private getBooksQueryOptions() { return queryOptions({ queryKey: BOOKS_QUERY_KEY, - queryFn: () => lastValueFrom(this.http.get(this.url)) + queryFn: () => lastValueFrom(this.http.get(this.url, {params: {stripForListView: false}})) }); }