fix(books): make "select all" actually select all not just the books loaded in (#533)
This commit is contained in:
@@ -31,6 +31,18 @@ public class AppBookController {
|
||||
return ResponseEntity.ok(mobileBookService.getBooks(request));
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "Get all book IDs matching filters",
|
||||
description = "Return all book IDs that match the given filters without pagination. Useful for bulk selection.",
|
||||
operationId = "appGetAllBookIds"
|
||||
)
|
||||
@GetMapping("/ids")
|
||||
public ResponseEntity<List<Long>> getAllBookIds(
|
||||
@ModelAttribute BookListRequest request) {
|
||||
|
||||
return ResponseEntity.ok(mobileBookService.getAllBookIds(request));
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "Get app book details",
|
||||
description = "Retrieve detailed app-facing information for a single book.",
|
||||
|
||||
@@ -129,6 +129,33 @@ public class AppBookService {
|
||||
return buildPageResponse(bookPage, userId, pageNum, pageSize);
|
||||
}
|
||||
|
||||
public List<Long> getAllBookIds(BookListRequest req) {
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
Long userId = user.getId();
|
||||
Set<Long> accessibleLibraryIds = getAccessibleLibraryIds(user);
|
||||
|
||||
Specification<BookEntity> spec = buildSpecification(accessibleLibraryIds, userId, req);
|
||||
|
||||
if (req.magicShelfId() != null) {
|
||||
spec = spec.and(magicShelfBookService.toSpecification(userId, req.magicShelfId()));
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(req.unshelved())) {
|
||||
spec = spec.and(AppBookSpecification.unshelved());
|
||||
}
|
||||
|
||||
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
|
||||
Root<BookEntity> root = cq.from(BookEntity.class);
|
||||
cq.select(root.get("id"));
|
||||
|
||||
if (spec != null) {
|
||||
cq.where(spec.toPredicate(root, cq, cb));
|
||||
}
|
||||
|
||||
return entityManager.createQuery(cq).getResultList();
|
||||
}
|
||||
|
||||
public AppBookDetail getBookDetail(Long bookId) {
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
Long userId = user.getId();
|
||||
|
||||
@@ -21,6 +21,11 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.booklore.config.security.service.AuthenticationService;
|
||||
import org.booklore.model.dto.BookLoreUser;
|
||||
import org.booklore.model.enums.PermissionType;
|
||||
import org.booklore.model.websocket.LogNotification;
|
||||
import org.booklore.model.websocket.Topic;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
@@ -51,6 +56,7 @@ class BookCoverServiceTest {
|
||||
@Mock private MetadataWriterFactory metadataWriterFactory;
|
||||
@Mock private TransactionTemplate transactionTemplate;
|
||||
@Mock private Executor taskExecutor;
|
||||
@Mock private AuthenticationService authenticationService;
|
||||
|
||||
@InjectMocks
|
||||
private BookCoverService service;
|
||||
@@ -58,6 +64,7 @@ class BookCoverServiceTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
lenient().when(appProperties.isLocalStorage()).thenReturn(true);
|
||||
lenient().when(authenticationService.getAuthenticatedUser()).thenReturn(BookLoreUser.builder().username("testuser").build());
|
||||
}
|
||||
|
||||
private BookEntity buildBook(long id, boolean coverLocked) {
|
||||
|
||||
Reference in New Issue
Block a user