Refactors the get book slice

This commit is contained in:
BinaryAlley committed 2026-09-13 06:58:32 -07:00
1 parent 1d35cd01db
commit 8aaf9fe64e
17 files changed
+395 -347

No files matched your search

@@ -1,8 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBook;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
@@ -15,9 +14,9 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBook;
/// <summary>
/// API endpoint for the <c>/books/{id}</c> route.
/// API endpoint for the <c>/{libraryId}/books/{bookId}</c> route.
/// </summary>
public class GetBookEndpoint : BaseEndpoint<GetBookRequest, IResult>
public class GetBookEndpoint : BaseEndpoint<EmptyRequest, IResult>
{
private readonly IQueryHandler<GetBookQuery, Result<BookResponse>> _getBookQueryHandler;
@@ -35,20 +34,23 @@ public class GetBookEndpoint : BaseEndpoint<GetBookRequest, IResult>
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.GET);
Verbs(Http.GET);
Routes(ApiRoutes.Books.GET_BOOK_BY_ID);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the book identified by <paramref name="request"/>.
/// Gets the book identified by the route.
/// </summary>
/// <param name="request">The request containing the Id of the book to get.</param>
/// <param name="request">The request object.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetBookRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
{
Result<BookResponse> result = await _getBookQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
Result<BookResponse> result = await _getBookQueryHandler.HandleAsync(new GetBookQuery(libraryId, bookId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -4,7 +4,6 @@ using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
@@ -20,7 +19,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.B
/// Class used for providing a textual description for the <see cref="GetBookEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
public class GetBookEndpointSummary : Summary<GetBookEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetBookEndpointSummary"/> class.
@@ -28,13 +27,7 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
public GetBookEndpointSummary()
{
Summary = "Gets a book by its Id.";
Description = "Gets the full details of the book identified by the request, including the resolved names of its media contributors.";
ExampleRequest = new GetBookRequest(
Id: Guid.NewGuid().ToString()
);
RequestParam(r => r.Id, "The Id of the book to get. Required.");
Description = "Gets the full details of the book identified by the route, including the references to its media contributors.";
ResponseParam<BookResponse>(r => r.Id, "The Id of the book.");
ResponseParam<BookResponse>(r => r.LibraryId, "The Id of the media library the book belongs to.");
@@ -65,8 +58,8 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
ResponseParam<BookResponse>(r => r.Format, "The format of the book (e.g., Hardcover, Paperback), if applicable.");
ResponseParam<BookResponse>(r => r.Edition, "The edition of the book, if applicable.");
ResponseParam<BookResponse>(r => r.VolumeNumber, "The volume or book number in the series, if applicable.");
ResponseParam<BookResponse>(r => r.Series, "The series the book is part of, if applicable.");
ResponseParam<BookResponse>(r => r.Series!.Title, "The title of the series the book is part of.");
ResponseParam<BookResponse>(r => r.Series, "The series the book is part of. Book series are not yet supported and this is always null.");
ResponseParam<BookResponse>(r => r.Series!.Title, "The title of the series the book is part of. Book series are not yet supported and this is always null.");
ResponseParam<BookResponse>(r => r.ASIN, "The ASIN (Amazon Standard Identification Number) of the book, if applicable.");
ResponseParam<BookResponse>(r => r.GoodreadsId, "The Goodreads ID of the book, if applicable.");
ResponseParam<BookResponse>(r => r.LCCN, "The Library of Congress Control Number (LCCN) of the book, if applicable.");
@@ -77,7 +70,7 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
ResponseParam<BookResponse>(r => r.BarnesAndNobleId, "The Barnes & Noble ID of the book, if applicable.");
ResponseParam<BookResponse>(r => r.AppleBooksId, "The Apple Books ID of the book, if applicable.");
ResponseParam<BookResponse>(r => r.ISBNs, "The list of ISBN (International Standard Book Number) of the book.");
ResponseParam<BookResponse>(r => r.Contributors, "The list of media contributors starring in this book.");
ResponseParam<BookResponse>(r => r.Contributors, "The list of references to the media contributors that contributed to this book, each with the role they played.");
ResponseParam<BookResponse>(r => r.Ratings, "The list of ratings for the book.");
ResponseParam<BookResponse>(r => r.MetadataStatus, "The status of the metadata enrichment of the book.");
ResponseParam<BookResponse>(r => r.LastMetadataUpdateUtc, "The date and time when the metadata of the book was last enriched, if applicable.");
@@ -131,9 +124,7 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
Format: BookFormat.Paperback,
Edition: "50th Anniversary Edition",
VolumeNumber: 1,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
Series: null,
ASIN: "B007978NPG",
GoodreadsId: "3",
LCCN: "54009621",
@@ -156,25 +147,13 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
],
Contributors:
[
new MediaContributorDto(
Name: new MediaContributorNameDto(
DisplayName: "J.R.R. Tolkien",
LegalName: "John Ronald Reuel Tolkien"
),
Role: new MediaContributorRoleDto(
Name: "author",
Category: MediaContributorRoleCategory.Author
)
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Author
),
new MediaContributorDto(
Name: new MediaContributorNameDto(
DisplayName: "Alan Lee",
LegalName: "Alan Lee"
),
Role: new MediaContributorRoleDto(
Name: "illustrator",
Category: MediaContributorRoleCategory.Illustrator
)
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Illustrator
)
],
Ratings:
@@ -202,13 +181,32 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
);
Response(401, "Authentication required.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/{id}"
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}"
}
}
);
@@ -219,7 +217,7 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books/{id}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
@@ -231,7 +229,7 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = "/api/v1/books/{id}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
@@ -243,12 +241,13 @@ public class GetBookEndpointSummary : Summary<GetBookEndpoint, GetBookRequest>
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books/{id}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"BookIdCannotBeEmpty"
}
}