Refactors the update book slice across the stack

This commit is contained in:
BinaryAlley committed 2026-09-12 12:13:18 -07:00
1 parent 9a71a6d32b
commit 001146eefc
27 files changed
+4065 -632

No files matched your search

@@ -3,6 +3,7 @@ using Lumina.Presentation.Web.Common.DTO.MediaContributors;
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary;
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -18,7 +19,12 @@ public class UpdateBookRequest
/// <summary>
/// Gets or sets the Id of the book to update, taken from the route.
/// </summary>
public string? Id { get; set; }
public string? BookId { get; set; }
/// <summary>
/// Gets or sets the Id of the media library the book belongs to.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the written content metadata of the book.
@@ -96,7 +102,7 @@ public class UpdateBookRequest
public List<IsbnDto>? ISBNs { get; set; }
/// <summary>
/// Gets or sets the list of media contributors of the book.
/// Gets or sets the list of media contributors of the book. Required.
/// </summary>
public List<MediaContributorDto>? Contributors { get; set; }
@@ -1,4 +1,4 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.SaveBook;
/// <summary>
/// API endpoint for the <c>/{culture}/library/written-content-library/books-library/books/{id}/api-save-book</c> route.
/// API endpoint for the <c>/{culture}/library/written-content-library/books-library/books/{bookId}/api-save-book</c> route.
/// </summary>
public class SaveBookEndpoint : BaseEndpoint<UpdateBookRequest, IResult>
{
@@ -50,14 +50,14 @@ public class SaveBookEndpoint : BaseEndpoint<UpdateBookRequest, IResult>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(UpdateBookRequest request, CancellationToken cancellationToken)
{
// The book is identified by the {id} route value, not by the id posted in the form, so that a mismatched id can never redirect
// The book is identified by the {bookId} route value, not by the id posted in the form, so that a mismatched id can never redirect
// the update to another book; the value is normalized to a Guid before it is substituted into the upstream URL, so that a crafted
// route value can never escape its URL segment, and an unparseable id is reported by the API as a missing book id.
string routeId = HttpContext.Request.RouteValues["id"]?.ToString() ?? string.Empty;
request.Id = Guid.TryParse(routeId, out Guid bookId) ? bookId.ToString() : Guid.Empty.ToString();
string routeId = HttpContext.Request.RouteValues["bookId"]?.ToString() ?? string.Empty;
request.BookId = Guid.TryParse(routeId, out Guid bookId) ? bookId.ToString() : Guid.Empty.ToString();
BookDetailsDto book = await _apiHttpClient.PutAsync<BookDetailsDto, UpdateBookRequest>(
ApiRoutes.Books.UPDATE_BOOK.Replace("{id}", request.Id), request, cancellationToken).ConfigureAwait(false);
ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId), request, cancellationToken).ConfigureAwait(false);
return JsonSuccess(book);
}
}
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Presentation.Web.Common.DTO.Common;
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary;
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
using Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Presentation.Web.Common.Enums.Common;
using System;
@@ -28,7 +29,8 @@ public class SaveBookEndpointSummary : Summary<SaveBookEndpoint, UpdateBookReque
Summary = "Updates a book.";
Description = "Updates the details of the book identified by the request.";
RequestParam(r => r.Id, "The unique identifier of the book to update. Required.");
RequestParam(r => r.BookId, "The unique identifier of the book to update. Required.");
RequestParam(r => r.LibraryId, "The Id of the media library the book belongs to. Required.");
RequestParam(r => r.Metadata, "The written content metadata of the book. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the book. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the book, if different from the current title. Optional.");
@@ -72,7 +74,8 @@ public class SaveBookEndpointSummary : Summary<SaveBookEndpoint, UpdateBookReque
ExampleRequest = new UpdateBookRequest
{
Id = Guid.NewGuid().ToString(),
BookId = Guid.NewGuid().ToString(),
LibraryId = Guid.NewGuid(),
Metadata = new WrittenContentMetadataDto
{
Title = "The Fellowship of the Ring",
@@ -140,12 +143,12 @@ public class SaveBookEndpointSummary : Summary<SaveBookEndpoint, UpdateBookReque
new MediaContributorDto
{
Name = new MediaContributorNameDto { DisplayName = "J.R.R. Tolkien", LegalName = "John Ronald Reuel Tolkien" },
Role = new MediaContributorRoleDto { Name = "author", Category = "Author" }
Role = MediaContributorRole.Author
},
new MediaContributorDto
{
Name = new MediaContributorNameDto { DisplayName = "Alan Lee", LegalName = "Alan Lee" },
Role = new MediaContributorRoleDto { Name = "illustrator", Category = "Illustrator" }
Role = MediaContributorRole.Illustrator
}
],
Ratings =