Refactors the add book slice and shared media contributor model across the stack

This commit is contained in:
BinaryAlley committed 2026-09-12 12:12:22 -07:00
1 parent 3a2c80b615
commit 9a71a6d32b
61 files changed
+5223 -1384

No files matched your search

@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.AddBook;
/// <summary>
/// API endpoint for the <c>/books</c> route.
/// API endpoint for the <c>/{libraryId}/books</c> route.
/// </summary>
public class AddBookEndpoint : BaseEndpoint<AddBookRequest, IResult>
{
@@ -48,7 +48,9 @@ public class AddBookEndpoint : BaseEndpoint<AddBookRequest, IResult>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddBookRequest request, CancellationToken cancellationToken)
{
Result<BookResponse> result = await _addBookCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Books.ADD_BOOK}/{result.Value.Id}", result.Value), Problem);
// take unique identifiers from the route
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
Result<BookResponse> result = await _addBookCommandHandler.HandleAsync(request.ToCommand(libraryId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1/libraries/{libraryId}/books/{result.Value.Id}", result.Value), Problem);
}
}
@@ -30,8 +30,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
Description = "Creates a new book and returns its details, including the location of the newly created resource.";
ExampleRequest = new AddBookRequest(
LibraryId: Guid.NewGuid(),
Path: "/books/the-fellowship-of-the-ring.epub",
Path: "/media/libraries/books/the-fellowship-of-the-ring.epub",
Metadata: new(
Title: "The Fellowship of the Ring",
OriginalTitle: "The Fellowship of the Ring",
@@ -95,24 +94,12 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
],
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: [
@@ -131,8 +118,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
]
);
RequestParam(r => r.LibraryId, "The Id of the media library this book belongs to. Required.");
RequestParam(r => r.Path, "The file system path of the book. Required.");
RequestParam(r => r.Path, "The file system path of the book. It must be inside one of the content locations of the media library that owns it. Required.");
RequestParam(r => r.Metadata, "Written content metadata of the book. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the written content. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the written content, if different from the current title. Optional.");
@@ -159,8 +145,8 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
RequestParam(r => r.Format, "The format of the book (e.g., Hardcover, Paperback). Optional.");
RequestParam(r => r.Edition, "The edition of the book. Optional.");
RequestParam(r => r.VolumeNumber, "The volume or book number in the series. Optional.");
RequestParam(r => r.Series, "The series name, if the book is part of a series. Optional.");
RequestParam(r => r.Series!.Title, "The title of the book series. Required.");
RequestParam(r => r.Series, "The series the book is part of. Book series are not yet supported and are ignored. Optional.");
RequestParam(r => r.Series!.Title, "The title of the book series. Book series are not yet supported and are ignored. Optional.");
RequestParam(r => r.ASIN, "The ASIN (Amazon Standard Identification Number) of the book. Optional.");
RequestParam(r => r.GoodreadsId, "The Goodreads Id of the book. Optional.");
RequestParam(r => r.LCCN, "The Library of Congress Control Number (LCCN) of the book. Optional.");
@@ -171,7 +157,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
RequestParam(r => r.BarnesAndNobleId, "The Barnes & Noble Id of the book. Optional.");
RequestParam(r => r.AppleBooksId, "The Apple Books Id of the book. Optional.");
RequestParam(r => r.ISBNs, "The list of ISBN (International Standard Book Number) of the book. Required.");
RequestParam(r => r.Contributors, "The list of media contributors (actors, directors, etc) starring in this book. Required.");
RequestParam(r => r.Contributors, "The list of media contributors of the book. Required.");
RequestParam(r => r.Ratings, "The list of ratings for this book. Required.");
ResponseParam<BookResponse>(r => r.Id, "The unique identifier of the book.");
@@ -203,8 +189,8 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
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.");
@@ -215,7 +201,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
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.");
@@ -228,7 +214,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
new BookResponse(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/books/the-fellowship-of-the-ring.epub",
Path: "/media/libraries/books/the-fellowship-of-the-ring.epub",
Metadata: new(
Title: "The Fellowship of the Ring",
OriginalTitle: "The Fellowship of the Ring",
@@ -294,24 +280,12 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
],
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: [
@@ -346,16 +320,16 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
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
{
@@ -363,7 +337,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/books"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books"
}
}
);
@@ -375,11 +349,59 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the media library or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "MediaContributorNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(409, "The request failed because a book with the same identity or path already exists.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "BookAlreadyExists",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "UniqueConstraintViolation",
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
{
@@ -387,14 +409,16 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"BookLibraryCannotBeNull",
"LibraryIdCannotBeEmpty",
"BookPathCannotBeEmpty",
"BookPathMustBeMaximum2048CharactersLong",
"BookPathMustBeWithinLibraryContentLocations",
"MetadataCannotBeNull",
"TitleCannotBeEmpty",
"TitleMustBeMaximum255CharactersLong",
@@ -403,7 +427,6 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
"ReleaseInfoCannotBeNull",
"OriginalReleaseYearMustBeBetween1And9999",
"ReReleaseYearMustBeBetween1And9999",
"CountryCodeMustBe2CharactersLong",
"ReleaseVersionMustBeMaximum50CharactersLong",
"OriginalReleaseDateAndYearMustMatch",
"ReReleaseDateAndYearMustMatch",
@@ -442,14 +465,8 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
"InvalidIsbn10Format",
"UnknownIsbnFormat",
"ContributorsListCannotBeNull",
"ContributorNameCannotBeEmpty",
"ContributorDisplayNameCannotBeEmpty",
"ContributorDisplayNameMustBeMaximum100CharactersLong",
"ContributorLegalNameMustBeMaximum100CharactersLong",
"ContributorRoleCannotBeNull",
"RoleNameCannotBeEmpty",
"RoleNameMustBeMaximum50CharactersLong",
"RoleCategoryCannotBeEmpty",
"MediaContributorIdCannotBeEmpty",
"UnknownMediaContributorRole",
"RatingsListCannotBeNull",
"RatingValueMustBePositive",
"RatingValueCannotBeGreaterThanMaxValue",