mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Refactors the get books and get books lite slices across the stack
This commit is contained in:
1 parent
001146eefc
commit
1d35cd01db
44 files changed
+1681
-418
No files matched your search
+6
-4
@@ -18,7 +18,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooks;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/books</c> route.
|
||||
/// API endpoint for the <c>/{libraryId}/books</c> route.
|
||||
/// </summary>
|
||||
public class GetBooksEndpoint : BaseEndpoint<GetBooksRequest, IResult>
|
||||
{
|
||||
@@ -45,13 +45,15 @@ public class GetBooksEndpoint : BaseEndpoint<GetBooksRequest, IResult>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of all the books of the media library identified by <paramref name="request"/>.
|
||||
/// Gets the list of all the books of the media library identified by the <c>libraryId</c> route parameter.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="request">The request containing the filtering and pagination options of the books to be retrieved.</param>
|
||||
/// <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<PaginatedResponse<BookResponse>> result = await _getBooksQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
// Take unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<PaginatedResponse<BookResponse>> result = await _getBooksQueryHandler.HandleAsync(request.ToQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+37
-49
@@ -27,25 +27,29 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
/// </summary>
|
||||
public GetBooksEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the list of books.";
|
||||
Description = "Returns the entire list of books.";
|
||||
Summary = "Retrieves the list of books of a media library.";
|
||||
Description = "Returns the paginated, filterable list of the books of the media library identified by the request, with the full details of each book. The page is returned to an Admin, who can see the books of all libraries, or to the owner of the library.";
|
||||
|
||||
ExampleRequest = new GetBooksRequest(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 48,
|
||||
PerPage: 10,
|
||||
SearchTerm: "fellowship",
|
||||
SortBy: "title",
|
||||
SortOrder: SortOrder.Ascending
|
||||
);
|
||||
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library whose books are retrieved. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of books to retrieve per page. Optional.");
|
||||
RequestParam(r => r.SearchTerm, "The search term used to filter results. Optional.");
|
||||
RequestParam(r => r.SortBy, "The name of the field by which to sort the results. Optional.");
|
||||
RequestParam(r => r.SortOrder, "The direction in which to sort the results. Optional.");
|
||||
|
||||
ResponseParam<PaginatedResponse<BookResponse>>(r => r.Data, "The books on the current page, each with the full details of the book.");
|
||||
ResponseParam<PaginatedResponse<BookResponse>>(r => r.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedResponse<BookResponse>>(r => r.PerPage, "The number of books retrieved per page.");
|
||||
ResponseParam<PaginatedResponse<BookResponse>>(r => r.Count, "The total number of books matching the request.");
|
||||
ResponseParam<PaginatedResponse<BookResponse>>(r => r.NumberOfPages, "The total number of pages.");
|
||||
|
||||
Response(200, "The paginated list of books is returned.",
|
||||
example: new PaginatedResponse<BookResponse>
|
||||
{
|
||||
@@ -93,9 +97,7 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
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",
|
||||
@@ -117,24 +119,12 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
],
|
||||
Contributors: [
|
||||
new(
|
||||
Name: new MediaContributorNameDto(
|
||||
DisplayName: "J.R.R. Tolkien",
|
||||
LegalName: "John Ronald Reuel Tolkien"
|
||||
),
|
||||
Role: new MediaContributorRoleDto(
|
||||
Name: "author",
|
||||
Category: MediaContributorRoleCategory.Author
|
||||
)
|
||||
ContributorId: Guid.NewGuid(),
|
||||
Role: MediaContributorRole.Author
|
||||
),
|
||||
new(
|
||||
Name: new MediaContributorNameDto(
|
||||
DisplayName: "Alan Lee",
|
||||
LegalName: "Alan Lee"
|
||||
),
|
||||
Role: new MediaContributorRoleDto(
|
||||
Name: "illustrator",
|
||||
Category: MediaContributorRoleCategory.Illustrator
|
||||
)
|
||||
ContributorId: Guid.NewGuid(),
|
||||
Role: MediaContributorRole.Illustrator
|
||||
)
|
||||
],
|
||||
Ratings: [
|
||||
@@ -200,9 +190,7 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
Format: BookFormat.Hardcover,
|
||||
Edition: "50th Anniversary Edition",
|
||||
VolumeNumber: 2,
|
||||
Series: new BookSeriesDto(
|
||||
Title: "The Lord of the Rings"
|
||||
),
|
||||
Series: null,
|
||||
ASIN: "B007978NPZ",
|
||||
GoodreadsId: "33",
|
||||
LCCN: "54009622",
|
||||
@@ -224,24 +212,12 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
],
|
||||
Contributors: [
|
||||
new(
|
||||
Name: new MediaContributorNameDto(
|
||||
DisplayName: "J.R.R. Tolkien",
|
||||
LegalName: "John Ronald Reuel Tolkien"
|
||||
),
|
||||
Role: new MediaContributorRoleDto(
|
||||
Name: "author",
|
||||
Category: MediaContributorRoleCategory.Author
|
||||
)
|
||||
ContributorId: Guid.NewGuid(),
|
||||
Role: MediaContributorRole.Author
|
||||
),
|
||||
new(
|
||||
Name: new MediaContributorNameDto(
|
||||
DisplayName: "Alan Lee",
|
||||
LegalName: "Alan Lee"
|
||||
),
|
||||
Role: new MediaContributorRoleDto(
|
||||
Name: "illustrator",
|
||||
Category: MediaContributorRoleCategory.Illustrator
|
||||
)
|
||||
ContributorId: Guid.NewGuid(),
|
||||
Role: MediaContributorRole.Illustrator
|
||||
)
|
||||
],
|
||||
Ratings: [
|
||||
@@ -282,16 +258,16 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/books"
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books"
|
||||
},
|
||||
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"
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -299,11 +275,23 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/books"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
@@ -311,7 +299,7 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint, GetBooksRequest
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/books",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
+6
-4
@@ -17,7 +17,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooksLite;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/books/lite</c> route.
|
||||
/// API endpoint for the <c>/{libraryId}/books/lite</c> route.
|
||||
/// </summary>
|
||||
public class GetBooksLiteEndpoint : BaseEndpoint<GetBooksLiteRequest, IResult>
|
||||
{
|
||||
@@ -44,13 +44,15 @@ public class GetBooksLiteEndpoint : BaseEndpoint<GetBooksLiteRequest, IResult>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight details of all the books of the media library identified by <paramref name="request"/>.
|
||||
/// Gets the lightweight details of all the books of the media library identified by the <c>libraryId</c> route parameter.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="request">The request containing the filtering and pagination options of the books to be 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);
|
||||
// Take unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<PaginatedResponse<BookLiteResponse>> result = await _getBooksLiteQueryHandler.HandleAsync(request.ToQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+27
-11
@@ -22,13 +22,12 @@ public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint, GetBook
|
||||
/// </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.";
|
||||
Summary = "Retrieves the list of lightweight book details of a media library.";
|
||||
Description = "Returns the paginated, filterable list of the lightweight details of the books of the media library identified by the request, suitable for card-style navigation. The page is returned to an Admin, who can see the books of all libraries, or to the owner of the library.";
|
||||
|
||||
ExampleRequest = new GetBooksLiteRequest(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 48,
|
||||
PerPage: 10,
|
||||
SearchTerm: "fellowship",
|
||||
FilterAlphaKey: "f",
|
||||
ShouldIgnoreThePrefixForAlphaPicker: true,
|
||||
@@ -36,7 +35,6 @@ public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint, GetBook
|
||||
SortOrder: SortOrder.Ascending
|
||||
);
|
||||
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library whose books are retrieved. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of books to retrieve per page. Optional.");
|
||||
RequestParam(r => r.SearchTerm, "The search term used to filter results. Optional.");
|
||||
@@ -45,6 +43,12 @@ public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint, GetBook
|
||||
RequestParam(r => r.SortBy, "The name of the field by which to sort the results. Optional.");
|
||||
RequestParam(r => r.SortOrder, "The direction in which to sort the results. Optional.");
|
||||
|
||||
ResponseParam<PaginatedResponse<BookLiteResponse>>(r => r.Data, "The lightweight book details on the current page.");
|
||||
ResponseParam<PaginatedResponse<BookLiteResponse>>(r => r.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedResponse<BookLiteResponse>>(r => r.PerPage, "The number of books retrieved per page.");
|
||||
ResponseParam<PaginatedResponse<BookLiteResponse>>(r => r.Count, "The total number of books matching the request.");
|
||||
ResponseParam<PaginatedResponse<BookLiteResponse>>(r => r.NumberOfPages, "The total number of pages.");
|
||||
|
||||
Response(200, "The paginated list of lightweight book details is returned.",
|
||||
example: new PaginatedResponse<BookLiteResponse>
|
||||
{
|
||||
@@ -77,16 +81,16 @@ public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint, GetBook
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/books/lite"
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/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"
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/lite"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -94,11 +98,23 @@ public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint, GetBook
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/books/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/lite"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/lite",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
@@ -106,7 +122,7 @@ public class GetBooksLiteEndpointSummary : Summary<GetBooksLiteEndpoint, GetBook
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/books/lite",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/lite",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user