From 8918b270e6ce0db67be863b2047eecd829dc44ac Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Sun, 1 Nov 2026 09:28:14 +0200 Subject: [PATCH] Removes the redundant BookRepository.GetByLibraryIdAsync --- .../BookLibrary/IBookRepository.cs | 8 ------ .../BookLibrary/BookRepository.cs | 19 -------------- .../BookLibrary/BookRepositoryTests.cs | 25 ++++++++++--------- 3 files changed, 13 insertions(+), 39 deletions(-) diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs index 48192b99..5c81dd64 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs @@ -23,14 +23,6 @@ public interface IBookRepository : IRepository, IGetAllLiteRepositoryAction, IDeleteByIdRepositoryAction { - /// - /// Gets all the books of the media library identified by . - /// - /// The Id of the media library whose books are retrieved. - /// Cancellation token that can be used to stop the execution. - /// An containing either a collection of , or an error. - Task>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken); - /// /// Gets the book of the media library identified by that is stored at the provided . /// diff --git a/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs b/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs index 2f51f1f8..e782bd58 100644 --- a/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs @@ -269,25 +269,6 @@ internal sealed class BookRepository : IBookRepository }; } - /// - /// Gets all the books of the media library identified by . - /// - /// The Id of the media library whose books are retrieved. - /// Cancellation token that can be used to stop the execution. - /// An containing either a collection of , or an error. - public async Task>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken) - { - return await _luminaDbContext.Books - .Include(book => book.Tags) - .Include(book => book.Genres) - .Include(book => book.ISBNs) - .Include(book => book.Contributors) - .Include(book => book.Artwork) - .AsSplitQuery() - .Where(book => book.LibraryId == libraryId) - .ToListAsync(cancellationToken).ConfigureAwait(false); - } - /// /// Gets the book of the media library identified by that is stored at the provided . /// diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs index 58beab2e..9f3aa5ef 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs @@ -262,7 +262,7 @@ public class BookRepositoryTests } [Fact] - public async Task GetByLibraryIdAsync_WhenCalled_ShouldReturnOnlyBooksOfTheLibrary() + public async Task GetAllAsync_WhenOtherLibrariesHaveBooks_ShouldReturnOnlyBooksOfTheFilteredLibrary() { // Arrange Guid libraryId = Guid.NewGuid(); @@ -272,13 +272,14 @@ public class BookRepositoryTests bookOfAnotherLibrary.LibraryId = Guid.NewGuid(); _mockContext.Books.AddRange(bookOfLibrary, bookOfAnotherLibrary); await _mockContext.SaveChangesAsync(); + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId); // Act - Result> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None); + Result> result = await _sut.GetAllAsync(filterModel: filter, cancellationToken: CancellationToken.None); // Assert Assert.False(result.IsFailure); - BookEntity retrievedBook = Assert.Single(result.Value); + BookEntity retrievedBook = Assert.Single(result.Value.Data); Assert.Equal(bookOfLibrary.Id, retrievedBook.Id); } @@ -1544,8 +1545,8 @@ public class BookRepositoryTests public async Task GetByIdsAsync_WhenExactlyFiveHundredIdsAreRequested_ShouldReturnEveryBook() { // Arrange - const int bookCount = 500; - List books = CreateBooks(bookCount); + const int BOOK_COUNT = 500; + List books = CreateBooks(BOOK_COUNT); _mockContext.Books.AddRange(books); await _mockContext.SaveChangesAsync(); @@ -1555,7 +1556,7 @@ public class BookRepositoryTests // Assert Assert.False(result.IsFailure); - Assert.Equal(bookCount, result.Value.Count); + Assert.Equal(BOOK_COUNT, result.Value.Count); Assert.Equal( books.Select(book => book.Id).OrderBy(id => id), result.Value.Select(book => book.Id).OrderBy(id => id)); @@ -1565,8 +1566,8 @@ public class BookRepositoryTests public async Task GetByIdsAsync_WhenMoreThanFiveHundredIdsAreRequested_ShouldReturnEveryBook() { // Arrange - const int bookCount = 501; - List books = CreateBooks(bookCount); + const int BOOK_COUNT = 501; + List books = CreateBooks(BOOK_COUNT); _mockContext.Books.AddRange(books); await _mockContext.SaveChangesAsync(); @@ -1576,7 +1577,7 @@ public class BookRepositoryTests // Assert Assert.False(result.IsFailure); - Assert.Equal(bookCount, result.Value.Count); + Assert.Equal(BOOK_COUNT, result.Value.Count); Assert.Equal( books.Select(book => book.Id).OrderBy(id => id), result.Value.Select(book => book.Id).OrderBy(id => id)); @@ -1656,8 +1657,8 @@ public class BookRepositoryTests public async Task GetAuthorsDisplayNamesByBookIdsAsync_WhenMoreThanFiveHundredIdsAreRequested_ShouldReturnTheAuthorOfEveryRequestedBook() { // Arrange - const int bookCount = 501; - List books = CreateBooks(bookCount); + const int BOOK_COUNT = 501; + List books = CreateBooks(BOOK_COUNT); _mockContext.Books.AddRange(books); MediaContributorEntity author = _mediaContributorEntityFixture.Create(displayName: "Shared Author"); _mockContext.MediaContributors.Add(author); @@ -1673,7 +1674,7 @@ public class BookRepositoryTests // Assert Assert.False(result.IsFailure); - Assert.Equal(bookCount, result.Value.Count); + Assert.Equal(BOOK_COUNT, result.Value.Count); Assert.All(result.Value.Keys, bookId => Assert.Equal("Shared Author", result.Value[bookId])); }