Refactors the get books and get books lite slices across the stack

This commit is contained in:
BinaryAlley committed 2026-09-13 04:16:59 -07:00
1 parent 001146eefc
commit 1d35cd01db
44 files changed
+1681 -418

No files matched your search

@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookLiteRow"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookLiteRowFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookLiteRow"/>.
/// </summary>
/// <param name="id">Optional. The Id of the book.</param>
/// <param name="title">Optional. The title of the book.</param>
/// <param name="releaseYear">Optional. The release year of the book.</param>
/// <param name="coverPath">Optional. The path of the cover image of the book.</param>
/// <returns>The created <see cref="BookLiteRow"/>.</returns>
public BookLiteRow Create(
Guid? id = null,
string? title = null,
int? releaseYear = null,
string? coverPath = null)
{
return new BookLiteRow
{
Id = id ?? _faker.Random.Guid(),
Title = title ?? _faker.Lorem.Sentence(),
ReleaseYear = releaseYear,
CoverPath = coverPath
};
}
/// <summary>
/// Creates a list of <see cref="BookLiteRow"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookLiteRow"/> instances.</returns>
public List<BookLiteRow> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
using Lumina.Application.Fixtures.Common.DTO.Pagination;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -19,36 +18,32 @@ namespace Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.Bo
public class GetBooksQueryFixture
{
private readonly Faker _faker = new();
private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new();
/// <summary>
/// Creates a random valid query to get books.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose books are retrieved.</param>
/// <param name="libraryId">Optional. The Id of the media library whose books are retrieved, taken from the route.</param>
/// <param name="paginationData">Optional. The pagination data of the query.</param>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePaginationData">Whether the pagination data should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created query to get books.</returns>
public GetBooksQuery Create(
Guid? libraryId = null,
string? libraryId = null,
PaginationDataDto? paginationData = null,
string? searchTerm = null,
string? sortBy = null,
SortOrder? sortOrder = null,
bool includeLibraryId = true,
bool includePaginationData = true)
{
return new GetBooksQuery(
includePaginationData ? paginationData ?? new PaginationDataDto
{
CurrentPage = _faker.Random.Number(1, 100),
PerPage = _faker.Random.Number(1, 200)
} : null,
new LibraryFilterDto
{
LibraryId = libraryId ?? _faker.Random.Guid(),
SearchTerm = searchTerm
},
includeLibraryId ? (libraryId ?? _faker.Random.Guid().ToString()) : null,
includePaginationData ? (paginationData ?? _paginationDataDtoFixture.Create()) : null,
searchTerm,
sortBy,
sortOrder ?? _faker.PickRandom<SortOrder>()
);
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooksLite;
using Lumina.Application.Fixtures.Common.DTO.Pagination;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -19,42 +18,38 @@ namespace Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.Bo
public class GetBooksLiteQueryFixture
{
private readonly Faker _faker = new();
private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new();
/// <summary>
/// Creates a random valid query to get the lightweight details of books.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose books are retrieved.</param>
/// <param name="libraryId">Optional. The Id of the media library whose books are retrieved, taken from the route.</param>
/// <param name="paginationData">Optional. The pagination data of the query.</param>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their title, for the alpha picker.</param>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePaginationData">Whether the pagination data should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created query to get the lightweight details of books.</returns>
public GetBooksLiteQuery Create(
Guid? libraryId = null,
string? libraryId = null,
PaginationDataDto? paginationData = null,
string? searchTerm = null,
string? filterAlphaKey = null,
bool shouldIgnoreThePrefixForAlphaPicker = false,
string? sortBy = null,
SortOrder? sortOrder = null,
bool includeLibraryId = true,
bool includePaginationData = true)
{
return new GetBooksLiteQuery(
includePaginationData ? paginationData ?? new PaginationDataDto
{
CurrentPage = _faker.Random.Number(1, 100),
PerPage = _faker.Random.Number(1, 200)
} : null,
new LibraryFilterDto
{
LibraryId = libraryId ?? _faker.Random.Guid(),
SearchTerm = searchTerm,
FilterAlphaKey = filterAlphaKey,
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker
},
includeLibraryId ? (libraryId ?? _faker.Random.Guid().ToString()) : null,
includePaginationData ? (paginationData ?? _paginationDataDtoFixture.Create()) : null,
searchTerm,
filterAlphaKey,
shouldIgnoreThePrefixForAlphaPicker,
sortBy,
sortOrder ?? _faker.PickRandom<SortOrder>()
);