fix(opds): add library restrictions to shelf OPDS catalogs (#1731)
This commit is contained in:
@@ -115,36 +115,58 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
|||||||
LEFT JOIN b.metadata m
|
LEFT JOIN b.metadata m
|
||||||
JOIN b.shelves s
|
JOIN b.shelves s
|
||||||
WHERE (b.deleted IS NULL OR b.deleted = false)
|
WHERE (b.deleted IS NULL OR b.deleted = false)
|
||||||
|
AND b.library.id IN :libraryIds
|
||||||
AND s.id IN :shelfIds
|
AND s.id IN :shelfIds
|
||||||
AND (
|
AND (
|
||||||
m.searchText LIKE CONCAT('%', :text, '%')
|
m.searchText LIKE CONCAT('%', :text, '%')
|
||||||
)
|
)
|
||||||
ORDER BY b.addedOn DESC
|
ORDER BY b.addedOn DESC
|
||||||
""")
|
""")
|
||||||
Page<Long> findBookIdsByMetadataSearchAndShelfIds(@Param("text") String text, @Param("shelfIds") Collection<Long> shelfIds, Pageable pageable);
|
Page<Long> findBookIdsByMetadataSearchAndShelfIds(@Param("text") String text, @Param("libraryIds") Collection<Long> libraryIds, @Param("shelfIds") Collection<Long> shelfIds, Pageable pageable);
|
||||||
|
|
||||||
@EntityGraph(attributePaths = {"metadata", "metadata.authors", "metadata.categories", "bookFiles", "shelves"})
|
@EntityGraph(attributePaths = {"metadata", "metadata.authors", "metadata.categories", "bookFiles", "shelves"})
|
||||||
@Query("SELECT DISTINCT b FROM BookEntity b JOIN b.shelves s WHERE b.id IN :ids AND s.id IN :shelfIds AND (b.deleted IS NULL OR b.deleted = false)")
|
@Query("""
|
||||||
List<BookEntity> findAllWithFullMetadataByIdsAndShelfIds(@Param("ids") Collection<Long> ids, @Param("shelfIds") Collection<Long> shelfIds);
|
SELECT DISTINCT b FROM BookEntity b
|
||||||
|
JOIN b.shelves s
|
||||||
|
WHERE
|
||||||
|
b.id IN :ids
|
||||||
|
AND b.library.id IN :libraryIds
|
||||||
|
AND s.id IN :shelfIds
|
||||||
|
AND (b.deleted IS NULL OR b.deleted = false)
|
||||||
|
""")
|
||||||
|
List<BookEntity> findAllWithFullMetadataByIdsAndShelfIds(@Param("ids") Collection<Long> ids, @Param("libraryIds") Collection<Long> libraryIds, @Param("shelfIds") Collection<Long> shelfIds);
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// BOOKS BY SHELF IDs - Two Query Pattern
|
// BOOKS BY SHELF IDs - Two Query Pattern
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
@Query("SELECT DISTINCT b.id FROM BookEntity b JOIN b.shelves s WHERE s.id IN :shelfIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC")
|
@Query("""
|
||||||
Page<Long> findBookIdsByShelfIds(@Param("shelfIds") Collection<Long> shelfIds, Pageable pageable);
|
SELECT DISTINCT b.id FROM BookEntity b
|
||||||
|
JOIN b.shelves s
|
||||||
|
WHERE
|
||||||
|
b.library.id IN :libraryIds
|
||||||
|
AND s.id IN :shelfIds
|
||||||
|
AND (b.deleted IS NULL OR b.deleted = false)
|
||||||
|
ORDER BY b.addedOn DESC
|
||||||
|
""")
|
||||||
|
Page<Long> findBookIdsByShelfIds(@Param("libraryIds") Collection<Long> libraryIds, @Param("shelfIds") Collection<Long> shelfIds, Pageable pageable);
|
||||||
|
|
||||||
@EntityGraph(attributePaths = {"metadata", "bookFiles", "shelves"})
|
@EntityGraph(attributePaths = {"metadata", "bookFiles", "shelves"})
|
||||||
@Query("SELECT DISTINCT b FROM BookEntity b JOIN b.shelves s WHERE b.id IN :ids AND s.id IN :shelfIds AND (b.deleted IS NULL OR b.deleted = false)")
|
@Query("""
|
||||||
List<BookEntity> findAllWithMetadataByIdsAndShelfIds(@Param("ids") Collection<Long> ids, @Param("shelfIds") Collection<Long> shelfIds);
|
SELECT DISTINCT b FROM BookEntity b
|
||||||
|
JOIN b.shelves s
|
||||||
|
WHERE
|
||||||
|
b.id IN :ids
|
||||||
|
AND b.library.id IN :libraryIds
|
||||||
|
AND s.id IN :shelfIds
|
||||||
|
AND (b.deleted IS NULL OR b.deleted = false)
|
||||||
|
""")
|
||||||
|
List<BookEntity> findAllWithMetadataByIdsAndShelfIds(@Param("ids") Collection<Long> ids, @Param("libraryIds") Collection<Long> libraryIds, @Param("shelfIds") Collection<Long> shelfIds);
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// RANDOM BOOKS - "Surprise Me" Feed
|
// RANDOM BOOKS - "Surprise Me" Feed
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
@Query("SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) ORDER BY function('RAND')")
|
|
||||||
List<Long> findRandomBookIds(Pageable pageable);
|
|
||||||
|
|
||||||
@Query("SELECT b.id FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY function('RAND')")
|
@Query("SELECT b.id FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY function('RAND')")
|
||||||
List<Long> findRandomBookIdsByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
List<Long> findRandomBookIdsByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||||
|
|
||||||
|
|||||||
@@ -82,15 +82,13 @@ public class OpdsBookService {
|
|||||||
|
|
||||||
BookLoreUser user = bookLoreUserTransformer.toDTO(entity);
|
BookLoreUser user = bookLoreUserTransformer.toDTO(entity);
|
||||||
boolean isAdmin = user.getPermissions().isAdmin();
|
boolean isAdmin = user.getPermissions().isAdmin();
|
||||||
Set<Long> userLibraryIds = user.getAssignedLibraries().stream()
|
Set<Long> userLibraryIds = getAccessibleLibraries(userId).stream().map(Library::getId).collect(Collectors.toSet());
|
||||||
.map(Library::getId)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
if (shelfIds != null && !shelfIds.isEmpty()) {
|
if (shelfIds != null && !shelfIds.isEmpty()) {
|
||||||
validateShelfAccess(shelfIds, user.getId(), isAdmin);
|
validateShelfAccess(shelfIds, user.getId(), isAdmin);
|
||||||
Page<Book> books = query != null && !query.isBlank()
|
Page<Book> books = query != null && !query.isBlank()
|
||||||
? searchByMetadataInShelvesPageInternal(BookUtils.normalizeForSearch(query), shelfIds, page, size, userId)
|
? searchByMetadataInShelvesPageInternal(BookUtils.normalizeForSearch(query), userLibraryIds, shelfIds, page, size, userId)
|
||||||
: getBooksByShelfIdsPageInternal(shelfIds, page, size, userId);
|
: getBooksByShelfIdsPageInternal(userLibraryIds, shelfIds, page, size, userId);
|
||||||
return applyBookFilters(books, userId);
|
return applyBookFilters(books, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,15 +357,15 @@ public class OpdsBookService {
|
|||||||
return createPageFromEntities(books, idPage, pageable, userId);
|
return createPageFromEntities(books, idPage, pageable, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Page<Book> getBooksByShelfIdsPageInternal(Set<Long> shelfIds, int page, int size, Long userId) {
|
private Page<Book> getBooksByShelfIdsPageInternal(Set<Long> libraryIds, Set<Long> shelfIds, int page, int size, Long userId) {
|
||||||
Pageable pageable = PageRequest.of(Math.max(page, 0), size);
|
Pageable pageable = PageRequest.of(Math.max(page, 0), size);
|
||||||
|
|
||||||
Page<Long> idPage = bookOpdsRepository.findBookIdsByShelfIds(shelfIds, pageable);
|
Page<Long> idPage = bookOpdsRepository.findBookIdsByShelfIds(libraryIds, shelfIds, pageable);
|
||||||
if (idPage.isEmpty()) {
|
if (idPage.isEmpty()) {
|
||||||
return new PageImpl<>(List.of(), pageable, 0);
|
return new PageImpl<>(List.of(), pageable, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BookEntity> books = bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(idPage.getContent(), shelfIds);
|
List<BookEntity> books = bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(idPage.getContent(), libraryIds, shelfIds);
|
||||||
return createPageFromEntities(books, idPage, pageable, userId);
|
return createPageFromEntities(books, idPage, pageable, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,15 +393,15 @@ public class OpdsBookService {
|
|||||||
return createPageFromEntities(books, idPage, pageable, userId);
|
return createPageFromEntities(books, idPage, pageable, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Page<Book> searchByMetadataInShelvesPageInternal(String text, Set<Long> shelfIds, int page, int size, Long userId) {
|
private Page<Book> searchByMetadataInShelvesPageInternal(String text, Set<Long> libraryIds, Set<Long> shelfIds, int page, int size, Long userId) {
|
||||||
Pageable pageable = PageRequest.of(Math.max(page, 0), size);
|
Pageable pageable = PageRequest.of(Math.max(page, 0), size);
|
||||||
|
|
||||||
Page<Long> idPage = bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(text, shelfIds, pageable);
|
Page<Long> idPage = bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(text, libraryIds, shelfIds, pageable);
|
||||||
if (idPage.isEmpty()) {
|
if (idPage.isEmpty()) {
|
||||||
return new PageImpl<>(List.of(), pageable, 0);
|
return new PageImpl<>(List.of(), pageable, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BookEntity> books = bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(idPage.getContent(), shelfIds);
|
List<BookEntity> books = bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(idPage.getContent(), libraryIds, shelfIds);
|
||||||
return createPageFromEntities(books, idPage, pageable, userId);
|
return createPageFromEntities(books, idPage, pageable, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,17 +156,17 @@ class OpdsBookServiceTest {
|
|||||||
when(bookOpdsRepository.findRecentBookIds(any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findRecentBookIds(any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByLibraryIds(anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByLibraryIds(anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByShelfId(anyLong(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByShelfId(anyLong(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByMetadataSearch(anyString(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByMetadataSearch(anyString(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByMetadataSearchAndLibraryIds(anyString(), anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByMetadataSearchAndLibraryIds(anyString(), anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(anyString(), anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(anyString(), anySet(), anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIds(anyList())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIds(anyList())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfId(anyList(), anyLong())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfId(anyList(), anyLong())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(anyList(), anySet(), anySet())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIds(anyList())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithFullMetadataByIds(anyList())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(anyList(), anySet(), anySet())).thenReturn(List.of());
|
||||||
|
|
||||||
opdsBookService.getBooksPage(details.getOpdsUserV2().getUserId(), "q", 1L, Set.of(2L), 0, 10);
|
opdsBookService.getBooksPage(details.getOpdsUserV2().getUserId(), "q", 1L, Set.of(2L), 0, 10);
|
||||||
}
|
}
|
||||||
@@ -178,16 +178,16 @@ class OpdsBookServiceTest {
|
|||||||
when(bookOpdsRepository.findRecentBookIds(any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findRecentBookIds(any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByLibraryIds(anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByLibraryIds(anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByShelfId(anyLong(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByShelfId(anyLong(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByMetadataSearch(anyString(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByMetadataSearch(anyString(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(anyString(), anySet(), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(anyString(), anySet(), anySet(), any())).thenReturn(Page.empty());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIds(anyList())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIds(anyList())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfId(anyList(), anyLong())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfId(anyList(), anyLong())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(anyList(), anySet(), anySet())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIds(anyList())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithFullMetadataByIds(anyList())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndLibraryIds(anyList(), anySet())).thenReturn(List.of());
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(anyList(), anySet())).thenReturn(List.of());
|
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(anyList(), anySet(), anySet())).thenReturn(List.of());
|
||||||
|
|
||||||
BookLoreUserEntity entity = mock(BookLoreUserEntity.class);
|
BookLoreUserEntity entity = mock(BookLoreUserEntity.class);
|
||||||
var permissionsEntity = mock(UserPermissionsEntity.class);
|
var permissionsEntity = mock(UserPermissionsEntity.class);
|
||||||
@@ -378,13 +378,13 @@ class OpdsBookServiceTest {
|
|||||||
Book book = Book.builder().id(1L).build();
|
Book book = Book.builder().id(1L).build();
|
||||||
when(bookMapper.toBook(bookEntity)).thenReturn(book);
|
when(bookMapper.toBook(bookEntity)).thenReturn(book);
|
||||||
|
|
||||||
when(bookOpdsRepository.findBookIdsByShelfIds(eq(Set.of(10L)), any())).thenReturn(new PageImpl<>(List.of(1L)));
|
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), eq(Set.of(10L)), any())).thenReturn(new PageImpl<>(List.of(1L)));
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(eq(List.of(1L)), eq(Set.of(10L)))).thenReturn(List.of(bookEntity));
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(eq(List.of(1L)), anySet(), eq(Set.of(10L)))).thenReturn(List.of(bookEntity));
|
||||||
|
|
||||||
Page<Book> result = opdsBookService.getBooksPage(1L, null, null, Set.of(10L), 0, 10);
|
Page<Book> result = opdsBookService.getBooksPage(1L, null, null, Set.of(10L), 0, 10);
|
||||||
|
|
||||||
assertThat(result.getContent()).hasSize(1);
|
assertThat(result.getContent()).hasSize(1);
|
||||||
verify(bookOpdsRepository).findBookIdsByShelfIds(eq(Set.of(10L)), any());
|
verify(bookOpdsRepository).findBookIdsByShelfIds(anySet(), eq(Set.of(10L)), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -424,13 +424,13 @@ class OpdsBookServiceTest {
|
|||||||
when(bookMapper.toBook(bookEntity1)).thenReturn(book1);
|
when(bookMapper.toBook(bookEntity1)).thenReturn(book1);
|
||||||
when(bookMapper.toBook(bookEntity2)).thenReturn(book2);
|
when(bookMapper.toBook(bookEntity2)).thenReturn(book2);
|
||||||
|
|
||||||
when(bookOpdsRepository.findBookIdsByShelfIds(eq(Set.of(10L, 20L)), any())).thenReturn(new PageImpl<>(List.of(1L, 2L)));
|
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), eq(Set.of(10L, 20L)), any())).thenReturn(new PageImpl<>(List.of(1L, 2L)));
|
||||||
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(eq(List.of(1L, 2L)), eq(Set.of(10L, 20L)))).thenReturn(List.of(bookEntity1, bookEntity2));
|
when(bookOpdsRepository.findAllWithMetadataByIdsAndShelfIds(eq(List.of(1L, 2L)), anySet(), eq(Set.of(10L, 20L)))).thenReturn(List.of(bookEntity1, bookEntity2));
|
||||||
|
|
||||||
Page<Book> result = opdsBookService.getBooksPage(1L, null, null, Set.of(10L, 20L), 0, 10);
|
Page<Book> result = opdsBookService.getBooksPage(1L, null, null, Set.of(10L, 20L), 0, 10);
|
||||||
|
|
||||||
assertThat(result.getContent()).hasSize(2);
|
assertThat(result.getContent()).hasSize(2);
|
||||||
verify(bookOpdsRepository).findBookIdsByShelfIds(eq(Set.of(10L, 20L)), any());
|
verify(bookOpdsRepository).findBookIdsByShelfIds(anySet(), eq(Set.of(10L, 20L)), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -463,13 +463,13 @@ class OpdsBookServiceTest {
|
|||||||
Book book = Book.builder().id(1L).build();
|
Book book = Book.builder().id(1L).build();
|
||||||
when(bookMapper.toBook(bookEntity)).thenReturn(book);
|
when(bookMapper.toBook(bookEntity)).thenReturn(book);
|
||||||
|
|
||||||
when(bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(eq("test"), eq(Set.of(10L)), any())).thenReturn(new PageImpl<>(List.of(1L)));
|
when(bookOpdsRepository.findBookIdsByMetadataSearchAndShelfIds(eq("test"), anySet(), eq(Set.of(10L)), any())).thenReturn(new PageImpl<>(List.of(1L)));
|
||||||
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(eq(List.of(1L)), eq(Set.of(10L)))).thenReturn(List.of(bookEntity));
|
when(bookOpdsRepository.findAllWithFullMetadataByIdsAndShelfIds(eq(List.of(1L)), anySet(), eq(Set.of(10L)))).thenReturn(List.of(bookEntity));
|
||||||
|
|
||||||
Page<Book> result = opdsBookService.getBooksPage(1L, "test", null, Set.of(10L), 0, 10);
|
Page<Book> result = opdsBookService.getBooksPage(1L, "test", null, Set.of(10L), 0, 10);
|
||||||
|
|
||||||
assertThat(result.getContent()).hasSize(1);
|
assertThat(result.getContent()).hasSize(1);
|
||||||
verify(bookOpdsRepository).findBookIdsByMetadataSearchAndShelfIds(eq("test"), eq(Set.of(10L)), any());
|
verify(bookOpdsRepository).findBookIdsByMetadataSearchAndShelfIds(eq("test"), anySet(), eq(Set.of(10L)), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -527,12 +527,12 @@ class OpdsBookServiceTest {
|
|||||||
when(shelf.getUser()).thenReturn(shelfUser);
|
when(shelf.getUser()).thenReturn(shelfUser);
|
||||||
when(shelfRepository.findByIdWithUser(10L)).thenReturn(Optional.of(shelf));
|
when(shelfRepository.findByIdWithUser(10L)).thenReturn(Optional.of(shelf));
|
||||||
|
|
||||||
when(bookOpdsRepository.findBookIdsByShelfIds(eq(Set.of(10L)), any())).thenReturn(Page.empty());
|
when(bookOpdsRepository.findBookIdsByShelfIds(anySet(), eq(Set.of(10L)), any())).thenReturn(Page.empty());
|
||||||
|
|
||||||
Page<Book> result = opdsBookService.getBooksPage(1L, null, null, Set.of(10L), 0, 10);
|
Page<Book> result = opdsBookService.getBooksPage(1L, null, null, Set.of(10L), 0, 10);
|
||||||
|
|
||||||
assertThat(result).isNotNull();
|
assertThat(result).isNotNull();
|
||||||
verify(bookOpdsRepository).findBookIdsByShelfIds(eq(Set.of(10L)), any());
|
verify(bookOpdsRepository).findBookIdsByShelfIds(anySet(), eq(Set.of(10L)), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== validateBookContentAccess ====================
|
// ==================== validateBookContentAccess ====================
|
||||||
|
|||||||
Reference in New Issue
Block a user