Adds pagination and filtering to the API

This commit is contained in:
BinaryAlley committed 2026-08-16 03:10:47 -07:00
1 parent ad984910a2
commit ce4ebf36bc
59 files changed
+4423 -242

No files matched your search

@@ -4,6 +4,7 @@ using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.Common;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
@@ -21,13 +22,13 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.B
/// </summary>
public class GetBooksEndpoint : BaseEndpoint<GetBooksRequest, IResult>
{
private readonly IQueryHandler<GetBooksQuery, Result<IEnumerable<BookResponse>>> _getBooksQueryHandler;
private readonly IQueryHandler<GetBooksQuery, Result<PaginatedResponse<BookResponse>>> _getBooksQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetBooksEndpoint"/> class.
/// </summary>
/// <param name="getBooksQueryHandler">Injected service for handling get books queries.</param>
public GetBooksEndpoint(IQueryHandler<GetBooksQuery, Result<IEnumerable<BookResponse>>> getBooksQueryHandler)
public GetBooksEndpoint(IQueryHandler<GetBooksQuery, Result<PaginatedResponse<BookResponse>>> getBooksQueryHandler)
{
_getBooksQueryHandler = getBooksQueryHandler;
}
@@ -50,7 +51,7 @@ public class GetBooksEndpoint : BaseEndpoint<GetBooksRequest, IResult>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetBooksRequest request, CancellationToken cancellationToken)
{
Result<IEnumerable<BookResponse>> result = await _getBooksQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
Result<PaginatedResponse<BookResponse>> result = await _getBooksQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -3,6 +3,7 @@ using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.Common;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
@@ -27,221 +28,228 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint>
Description = "Returns the entire list of books.";
Response(200, "The list of books is returned.",
example: new BookResponse[] {
new(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/books/the-fellowship-of-the-ring.epub",
Metadata: new(
Title: "The Fellowship of the Ring",
OriginalTitle: "The Fellowship of the Ring",
Description: "The first part of J.R.R. Tolkien's epic adventure The Lord of the Rings. In a sleepy village in the Shire, young Frodo Baggins finds himself faced with an immense task, as his elderly cousin Bilbo entrusts the Ring to his care. Frodo must leave his home and make a perilous journey across Middle-earth to the Cracks of Doom, there to destroy the Ring and foil the Dark Lord in his evil purpose.",
ReleaseInfo: new(
OriginalReleaseDate: DateOnly.ParseExact("1954-07-29", "yyyy-MM-dd", null),
OriginalReleaseYear: 1954,
ReReleaseDate: DateOnly.ParseExact("2001-09-06", "yyyy-MM-dd", null),
ReReleaseYear: 2001,
ReleaseCountry: "uk",
ReleaseVersion: "50th Anniversary Edition"
),
Genres: new List<GenreDto>() {
{ new(Name: "fantasy") },
{ new(Name: "adventure") },
{ new(Name: "classic") }
},
Tags: new List<TagDto>() {
{ new(Name: "epic fantasy") },
{ new(Name: "quest") },
{ new(Name: "middle-earth") }
},
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Publisher: "Houghton Mifflin",
PageCount: 398
Response(200, "The paginated list of books is returned.",
example: new PaginatedResponse<BookResponse>
{
Data = [
new(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/books/the-fellowship-of-the-ring.epub",
Metadata: new(
Title: "The Fellowship of the Ring",
OriginalTitle: "The Fellowship of the Ring",
Description: "The first part of J.R.R. Tolkien's epic adventure The Lord of the Rings. In a sleepy village in the Shire, young Frodo Baggins finds himself faced with an immense task, as his elderly cousin Bilbo entrusts the Ring to his care. Frodo must leave his home and make a perilous journey across Middle-earth to the Cracks of Doom, there to destroy the Ring and foil the Dark Lord in his evil purpose.",
ReleaseInfo: new(
OriginalReleaseDate: DateOnly.ParseExact("1954-07-29", "yyyy-MM-dd", null),
OriginalReleaseYear: 1954,
ReReleaseDate: DateOnly.ParseExact("2001-09-06", "yyyy-MM-dd", null),
ReReleaseYear: 2001,
ReleaseCountry: "uk",
ReleaseVersion: "50th Anniversary Edition"
),
Genres: new List<GenreDto>() {
{ new(Name: "fantasy") },
{ new(Name: "adventure") },
{ new(Name: "classic") }
},
Tags: new List<TagDto>() {
{ new(Name: "epic fantasy") },
{ new(Name: "quest") },
{ new(Name: "middle-earth") }
},
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Publisher: "Houghton Mifflin",
PageCount: 398
),
Format: BookFormat.Paperback,
Edition: "50th Anniversary Edition",
VolumeNumber: 1,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
ASIN: "B007978NPG",
GoodreadsId: "3",
LCCN: "54009621",
OCLCNumber: "ocm00012345",
OpenLibraryId: "OL7603910M",
LibraryThingId: "3203347",
GoogleBooksId: "aWZzLPhY4o0C",
BarnesAndNobleId: "1100307790",
AppleBooksId: "id395211",
ISBNs: [
new(
Value: "0395272238",
Format: IsbnFormat.Isbn10
),
new(
Value: "9780395272237",
Format: IsbnFormat.Isbn13
)
],
Contributors: [
new(
Name: new MediaContributorNameDto(
DisplayName: "J.R.R. Tolkien",
LegalName: "John Ronald Reuel Tolkien"
Format: BookFormat.Paperback,
Edition: "50th Anniversary Edition",
VolumeNumber: 1,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
ASIN: "B007978NPG",
GoodreadsId: "3",
LCCN: "54009621",
OCLCNumber: "ocm00012345",
OpenLibraryId: "OL7603910M",
LibraryThingId: "3203347",
GoogleBooksId: "aWZzLPhY4o0C",
BarnesAndNobleId: "1100307790",
AppleBooksId: "id395211",
ISBNs: [
new(
Value: "0395272238",
Format: IsbnFormat.Isbn10
),
Role: new MediaContributorRoleDto(
Name: "author",
Category: "book"
new(
Value: "9780395272237",
Format: IsbnFormat.Isbn13
)
),
new(
Name: new MediaContributorNameDto(
DisplayName: "Alan Lee",
LegalName: "Alan Lee"
],
Contributors: [
new(
Name: new MediaContributorNameDto(
DisplayName: "J.R.R. Tolkien",
LegalName: "John Ronald Reuel Tolkien"
),
Role: new MediaContributorRoleDto(
Name: "author",
Category: "book"
)
),
Role: new MediaContributorRoleDto(
Name: "illustrator",
Category: "book"
new(
Name: new MediaContributorNameDto(
DisplayName: "Alan Lee",
LegalName: "Alan Lee"
),
Role: new MediaContributorRoleDto(
Name: "illustrator",
Category: "book"
)
)
)
],
Ratings: [
new(
Source: BookRatingSource.GoogleBooks,
Value: 4.36M,
MaxValue: 5,
VoteCount: 2345678
),
new(
Source: BookRatingSource.Amazon,
Value: 4.7M,
MaxValue: 5,
VoteCount: 87654
)
],
MetadataStatus: MetadataStatus.Pending,
LastMetadataUpdateUtc: default,
MetadataProvider: default,
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
),
new(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/books/the-two-towers.epub",
Metadata: new(
Title: "The Two Towers",
OriginalTitle: "The Two Towers",
Description: "The second part of J.R.R. Tolkien's epic adventure The Lord of the Rings. The Fellowship is scattered, and the quest to destroy the One Ring continues. Aragorn, Legolas, and Gimli search for Merry and Pippin, while Frodo and Sam take the Ring closer to Mordor under the guidance of the mysterious Gollum.",
ReleaseInfo: new(
OriginalReleaseDate: DateOnly.ParseExact("1954-11-11", "yyyy-MM-dd", null),
OriginalReleaseYear: 1954,
ReReleaseDate: DateOnly.ParseExact("2001-11-08", "yyyy-MM-dd", null),
ReReleaseYear: 2001,
ReleaseCountry: "uk",
ReleaseVersion: "50th Anniversary Edition"
),
Genres: new List<GenreDto>() {
{ new(Name: "fantasy") },
{ new(Name: "adventure") },
{ new(Name: "classic") }
},
Tags: new List<TagDto>() {
{ new(Name: "epic fantasy") },
{ new(Name: "quest") },
{ new(Name: "middle-earth") }
},
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Publisher: "Houghton Mifflin",
PageCount: 352
],
Ratings: [
new(
Source: BookRatingSource.GoogleBooks,
Value: 4.36M,
MaxValue: 5,
VoteCount: 2345678
),
new(
Source: BookRatingSource.Amazon,
Value: 4.7M,
MaxValue: 5,
VoteCount: 87654
)
],
MetadataStatus: MetadataStatus.Pending,
LastMetadataUpdateUtc: default,
MetadataProvider: default,
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
),
Format: BookFormat.Hardcover,
Edition: "50th Anniversary Edition",
VolumeNumber: 2,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
ASIN: "B007978NPZ",
GoodreadsId: "33",
LCCN: "54009622",
OCLCNumber: "ocm00067890",
OpenLibraryId: "OL7603911M",
LibraryThingId: "3203348",
GoogleBooksId: "aWZzLPhY4o1D",
BarnesAndNobleId: "1100307791",
AppleBooksId: "id395212",
ISBNs: [
new(
Value: "0395272246",
Format: IsbnFormat.Isbn10
),
new(
Value: "9780395272244",
Format: IsbnFormat.Isbn13
)
],
Contributors: [
new(
Name: new MediaContributorNameDto(
DisplayName: "J.R.R. Tolkien",
LegalName: "John Ronald Reuel Tolkien"
new(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/books/the-two-towers.epub",
Metadata: new(
Title: "The Two Towers",
OriginalTitle: "The Two Towers",
Description: "The second part of J.R.R. Tolkien's epic adventure The Lord of the Rings. The Fellowship is scattered, and the quest to destroy the One Ring continues. Aragorn, Legolas, and Gimli search for Merry and Pippin, while Frodo and Sam take the Ring closer to Mordor under the guidance of the mysterious Gollum.",
ReleaseInfo: new(
OriginalReleaseDate: DateOnly.ParseExact("1954-11-11", "yyyy-MM-dd", null),
OriginalReleaseYear: 1954,
ReReleaseDate: DateOnly.ParseExact("2001-11-08", "yyyy-MM-dd", null),
ReReleaseYear: 2001,
ReleaseCountry: "uk",
ReleaseVersion: "50th Anniversary Edition"
),
Role: new MediaContributorRoleDto(
Name: "author",
Category: "book"
)
),
new(
Name: new MediaContributorNameDto(
DisplayName: "Alan Lee",
LegalName: "Alan Lee"
Genres: new List<GenreDto>() {
{ new(Name: "fantasy") },
{ new(Name: "adventure") },
{ new(Name: "classic") }
},
Tags: new List<TagDto>() {
{ new(Name: "epic fantasy") },
{ new(Name: "quest") },
{ new(Name: "middle-earth") }
},
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Role: new MediaContributorRoleDto(
Name: "illustrator",
Category: "book"
)
)
],
Ratings: [
new(
Source: BookRatingSource.GoogleBooks,
Value: 4.4M,
MaxValue: 5,
VoteCount: 2340000
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Publisher: "Houghton Mifflin",
PageCount: 352
),
new(
Source: BookRatingSource.Amazon,
Value: 4.8M,
MaxValue: 5,
VoteCount: 90000
)
],
MetadataStatus: MetadataStatus.Pending,
LastMetadataUpdateUtc: default,
MetadataProvider: default,
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
)
Format: BookFormat.Hardcover,
Edition: "50th Anniversary Edition",
VolumeNumber: 2,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
ASIN: "B007978NPZ",
GoodreadsId: "33",
LCCN: "54009622",
OCLCNumber: "ocm00067890",
OpenLibraryId: "OL7603911M",
LibraryThingId: "3203348",
GoogleBooksId: "aWZzLPhY4o1D",
BarnesAndNobleId: "1100307791",
AppleBooksId: "id395212",
ISBNs: [
new(
Value: "0395272246",
Format: IsbnFormat.Isbn10
),
new(
Value: "9780395272244",
Format: IsbnFormat.Isbn13
)
],
Contributors: [
new(
Name: new MediaContributorNameDto(
DisplayName: "J.R.R. Tolkien",
LegalName: "John Ronald Reuel Tolkien"
),
Role: new MediaContributorRoleDto(
Name: "author",
Category: "book"
)
),
new(
Name: new MediaContributorNameDto(
DisplayName: "Alan Lee",
LegalName: "Alan Lee"
),
Role: new MediaContributorRoleDto(
Name: "illustrator",
Category: "book"
)
)
],
Ratings: [
new(
Source: BookRatingSource.GoogleBooks,
Value: 4.4M,
MaxValue: 5,
VoteCount: 2340000
),
new(
Source: BookRatingSource.Amazon,
Value: 4.8M,
MaxValue: 5,
VoteCount: 90000
)
],
MetadataStatus: MetadataStatus.Pending,
LastMetadataUpdateUtc: default,
MetadataProvider: default,
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
)
],
CurrentPage = 1,
PerPage = 10,
Count = 2,
NumberOfPages = 1
}
);
@@ -275,5 +283,26 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint>
}
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.Common;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooksLite;
/// <summary>
/// API endpoint for the <c>/books/lite</c> route.
/// </summary>
public class GetBooksLiteEndpoint : BaseEndpoint<GetBooksLiteRequest, IResult>
{
private readonly IQueryHandler<GetBooksLiteQuery, Result<PaginatedResponse<BookLiteResponse>>> _getBooksLiteQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetBooksLiteEndpoint"/> class.
/// </summary>
/// <param name="getBooksLiteQueryHandler">Injected service for handling get books lite queries.</param>
public GetBooksLiteEndpoint(IQueryHandler<GetBooksLiteQuery, Result<PaginatedResponse<BookLiteResponse>>> getBooksLiteQueryHandler)
{
_getBooksLiteQueryHandler = getBooksLiteQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Books.GET_BOOKS_LITE);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the lightweight details of all the books of the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library whose books are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetBooksLiteRequest request, CancellationToken cancellationToken)
{
Result<PaginatedResponse<BookLiteResponse>> result = await _getBooksLiteQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,101 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Responses.Common;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooksLite;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetBooksLiteEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetBooksLiteEndpointSummary"/> class.
/// </summary>
public GetBooksLiteEndpointSummary()
{
Summary = "Retrieves the lightweight details of the list of books.";
Description = "Returns a paginated list of the lightweight details of the books of the media library, suitable for card-style navigation.";
Response(200, "The paginated list of lightweight book details is returned.",
example: new PaginatedResponse<BookLiteResponse>
{
Data = [
new(
Id: Guid.NewGuid(),
Title: "The Fellowship of the Ring",
ReleaseYear: 1954,
CoverPath: null
),
new(
Id: Guid.NewGuid(),
Title: "The Two Towers",
ReleaseYear: 1954,
CoverPath: null
)
],
CurrentPage = 1,
PerPage = 10,
Count = 2,
NumberOfPages = 1
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/books/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/books/lite"
}
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books/lite",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}