Converts the web client request objects from classes to records.

This commit is contained in:
BinaryAlley committed 2026-10-12 19:21:52 +03:00
1 parent 5a27c22109
commit defbd9176f
26 files changed
+247 -383

No files matched your search

@@ -9,48 +9,26 @@ namespace Lumina.Presentation.Web.Common.Requests.Libraries;
/// <summary>
/// Represents a request to get the lightweight details of the books of a media library.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose books are retrieved. Required.</param>
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
/// <param name="PerPage">The maximum number of books to retrieve per page. Optional.</param>
/// <param name="SearchTerm">The search term used to filter results. Optional.</param>
/// <param name="FilterAlphaKey">
/// The alpha key used to filter the results by the first character of their title, for the alpha picker. Optional.
/// Can be <see langword="null"/> to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter,
/// "#" to filter by titles whose first character is a digit, or "*" to filter by titles whose first character is neither a letter nor a digit.
/// </param>
/// <param name="ShouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a title is ignored when computing the alpha key, or not. Optional.</param>
/// <param name="SortBy">The name of the field by which to sort the results. Optional.</param>
/// <param name="SortOrder">The direction in which to sort the results. Optional.</param>
[DebuggerDisplay("LibraryId: {LibraryId}")]
public class GetBooksLiteRequest
{
/// <summary>
/// Gets or sets the Id of the media library whose books are retrieved.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the page of results to retrieve.
/// </summary>
public int? CurrentPage { get; set; }
/// <summary>
/// Gets or sets the maximum number of books to retrieve per page.
/// </summary>
public int? PerPage { get; set; }
/// <summary>
/// Gets or sets the search term used to filter results.
/// </summary>
public string? SearchTerm { get; set; }
/// <summary>
/// Gets or sets the alpha key used to filter the results by the first character of their title, for the alpha picker.
/// Can be <see langword="null"/> to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter,
/// "#" to filter by titles whose first character is a digit, or "*" to filter by titles whose first character is neither a letter nor a digit.
/// </summary>
public string? FilterAlphaKey { get; set; }
/// <summary>
/// Gets or sets whether the leading "The " prefix of a title is ignored when computing the alpha key, or not.
/// </summary>
public bool ShouldIgnoreThePrefixForAlphaPicker { get; set; }
/// <summary>
/// Gets or sets the name of the field by which to sort the results.
/// </summary>
public string? SortBy { get; set; }
/// <summary>
/// Gets or sets the direction in which to sort the results.
/// </summary>
public SortOrder? SortOrder { get; set; }
}
public record GetBooksLiteRequest(
Guid LibraryId,
int? CurrentPage,
int? PerPage,
string? SearchTerm,
string? FilterAlphaKey,
bool ShouldIgnoreThePrefixForAlphaPicker,
string? SortBy,
SortOrder? SortOrder
);
@@ -13,101 +13,44 @@ namespace Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.
/// <summary>
/// Represents a request to update an existing book.
/// </summary>
/// <param name="BookId">The Id of the book to update, taken from the route. Required.</param>
/// <param name="LibraryId">The Id of the media library the book belongs to. Required.</param>
/// <param name="Metadata">The written content metadata of the book. Required.</param>
/// <param name="Format">The format of the book (e.g., Hardcover, Paperback). Optional.</param>
/// <param name="Edition">The edition of the book. Optional.</param>
/// <param name="VolumeNumber">The volume or book number in the series. Optional.</param>
/// <param name="Series">The series the book is part of. Optional.</param>
/// <param name="ASIN">The ASIN (Amazon Standard Identification Number) of the book. Optional.</param>
/// <param name="GoodreadsId">The Goodreads Id of the book. Optional.</param>
/// <param name="LCCN">The Library of Congress Control Number (LCCN) of the book. Optional.</param>
/// <param name="OCLCNumber">The OCLC Number (WorldCat identifier) of the book. Optional.</param>
/// <param name="OpenLibraryId">The Open Library Id of the book. Optional.</param>
/// <param name="LibraryThingId">The LibraryThing Id of the book. Optional.</param>
/// <param name="GoogleBooksId">The Google Books Id of the book. Optional.</param>
/// <param name="BarnesAndNobleId">The Barnes &amp; Noble Id of the book. Optional.</param>
/// <param name="AppleBooksId">The Apple Books Id of the book. Optional.</param>
/// <param name="ISBNs">The list of ISBN (International Standard Book Number) of the book. Required.</param>
/// <param name="Contributors">The list of media contributors of the book. Required.</param>
/// <param name="Ratings">The list of ratings of the book. Required.</param>
[DebuggerDisplay("Title: {Metadata?.Title}")]
public class UpdateBookRequest
{
/// <summary>
/// Gets or sets the Id of the book to update, taken from the route.
/// </summary>
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.
/// </summary>
public WrittenContentMetadataDto? Metadata { get; set; }
/// <summary>
/// Gets or sets the format of the book (e.g., Hardcover, Paperback), if applicable.
/// </summary>
public BookFormat? Format { get; set; }
/// <summary>
/// Gets or sets the edition of the book, if applicable.
/// </summary>
public string? Edition { get; set; }
/// <summary>
/// Gets or sets the volume or book number in the series, if applicable.
/// </summary>
public float? VolumeNumber { get; set; }
/// <summary>
/// Gets or sets the series name, if the book is part of a series.
/// </summary>
public BookSeriesDto? Series { get; set; }
/// <summary>
/// Gets or sets the ASIN (Amazon Standard Identification Number) of the book, if applicable.
/// </summary>
public string? ASIN { get; set; }
/// <summary>
/// Gets or sets the Goodreads Id of the book, if applicable.
/// </summary>
public string? GoodreadsId { get; set; }
/// <summary>
/// Gets or sets the Library of Congress Control Number (LCCN) of the book, if applicable.
/// </summary>
public string? LCCN { get; set; }
/// <summary>
/// Gets or sets the OCLC Number (WorldCat identifier) of the book, if applicable.
/// </summary>
public string? OCLCNumber { get; set; }
/// <summary>
/// Gets or sets the Open Library Id of the book, if applicable.
/// </summary>
public string? OpenLibraryId { get; set; }
/// <summary>
/// Gets or sets the LibraryThing Id of the book, if applicable.
/// </summary>
public string? LibraryThingId { get; set; }
/// <summary>
/// Gets or sets the Google Books Id of the book, if applicable.
/// </summary>
public string? GoogleBooksId { get; set; }
/// <summary>
/// Gets or sets the Barnes &amp; Noble Id of the book, if applicable.
/// </summary>
public string? BarnesAndNobleId { get; set; }
/// <summary>
/// Gets or sets the Apple Books Id of the book, if applicable.
/// </summary>
public string? AppleBooksId { get; set; }
/// <summary>
/// Gets or sets the list of ISBN (International Standard Book Number) of the book.
/// </summary>
public List<IsbnDto>? ISBNs { get; set; }
/// <summary>
/// Gets or sets the list of media contributors of the book. Required.
/// </summary>
public List<MediaContributorDto>? Contributors { get; set; }
/// <summary>
/// Gets or sets the list of ratings of the book.
/// </summary>
public List<BookRatingDto>? Ratings { get; set; }
}
public record UpdateBookRequest(
string? BookId,
Guid LibraryId,
WrittenContentMetadataDto? Metadata,
BookFormat? Format,
string? Edition,
float? VolumeNumber,
BookSeriesDto? Series,
string? ASIN,
string? GoodreadsId,
string? LCCN,
string? OCLCNumber,
string? OpenLibraryId,
string? LibraryThingId,
string? GoogleBooksId,
string? BarnesAndNobleId,
string? AppleBooksId,
List<IsbnDto>? ISBNs,
List<MediaContributorDto>? Contributors,
List<BookRatingDto>? Ratings
);
@@ -9,16 +9,10 @@ namespace Lumina.Presentation.Web.Common.Requests.Plugins;
/// <summary>
/// Represents a request to reorder the artwork providers of a media library.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose artwork providers are reordered. Required.</param>
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank. Required.</param>
[DebuggerDisplay("LibraryId: {LibraryId}")]
public class ReorderLibraryArtworkProvidersRequest
{
/// <summary>
/// Gets or sets the Id of the media library whose artwork providers are reordered.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the plugin Ids in the new order, from highest to lowest rank.
/// </summary>
public List<Guid> PluginIds { get; set; } = [];
}
public record ReorderLibraryArtworkProvidersRequest(
Guid LibraryId,
List<Guid> PluginIds
);
@@ -9,16 +9,10 @@ namespace Lumina.Presentation.Web.Common.Requests.Plugins;
/// <summary>
/// Represents a request to reorder the metadata providers of a media library.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose metadata providers are reordered. Required.</param>
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank. Required.</param>
[DebuggerDisplay("LibraryId: {LibraryId}")]
public class ReorderLibraryMetadataProvidersRequest
{
/// <summary>
/// Gets or sets the Id of the media library whose metadata providers are reordered.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the plugin Ids in the new order, from highest to lowest rank.
/// </summary>
public List<Guid> PluginIds { get; set; } = [];
}
public record ReorderLibraryMetadataProvidersRequest(
Guid LibraryId,
List<Guid> PluginIds
);
@@ -8,21 +8,12 @@ namespace Lumina.Presentation.Web.Common.Requests.Plugins;
/// <summary>
/// Represents a request to enable or disable a book reader for a media library.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose book reader is enabled or disabled. Required.</param>
/// <param name="PluginId">The unique identifier of the plugin providing the book reader. Required.</param>
/// <param name="IsEnabled">Whether the book reader should be enabled for the media library. Required.</param>
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
public class SetBookReaderEnabledRequest
{
/// <summary>
/// Gets or sets the Id of the media library whose book reader is enabled or disabled. Required.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the plugin providing the book reader. Required.
/// </summary>
public Guid PluginId { get; set; }
/// <summary>
/// Gets or sets whether the book reader should be enabled for the media library. Required.
/// </summary>
public bool IsEnabled { get; set; }
}
public record SetBookReaderEnabledRequest(
Guid LibraryId,
Guid PluginId,
bool IsEnabled
);
@@ -8,21 +8,12 @@ namespace Lumina.Presentation.Web.Common.Requests.Plugins;
/// <summary>
/// Represents a request to enable or disable an artwork provider for a media library.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose artwork provider is enabled or disabled. Required.</param>
/// <param name="PluginId">The unique identifier of the plugin providing the artwork. Required.</param>
/// <param name="IsEnabled">Whether the artwork provider should be enabled for the media library. Required.</param>
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
public class SetLibraryArtworkProviderEnabledRequest
{
/// <summary>
/// Gets or sets the Id of the media library whose artwork provider is enabled or disabled.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the plugin providing the artwork.
/// </summary>
public Guid PluginId { get; set; }
/// <summary>
/// Gets or sets whether the artwork provider should be enabled for the media library.
/// </summary>
public bool IsEnabled { get; set; }
}
public record SetLibraryArtworkProviderEnabledRequest(
Guid LibraryId,
Guid PluginId,
bool IsEnabled
);
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -9,21 +8,12 @@ namespace Lumina.Presentation.Web.Common.Requests.Plugins;
/// <summary>
/// Represents a request to enable or disable a metadata provider for a media library.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose metadata provider is enabled or disabled. Required.</param>
/// <param name="PluginId">The unique identifier of the plugin providing the metadata. Required.</param>
/// <param name="IsEnabled">Whether the metadata provider should be enabled for the media library. Required.</param>
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
public class SetLibraryMetadataProviderEnabledRequest
{
/// <summary>
/// Gets or sets the Id of the media library whose metadata provider is enabled or disabled.
/// </summary>
public Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the plugin providing the metadata.
/// </summary>
public Guid PluginId { get; set; }
/// <summary>
/// Gets or sets whether the metadata provider should be enabled for the media library.
/// </summary>
public bool IsEnabled { get; set; }
}
public record SetLibraryMetadataProviderEnabledRequest(
Guid LibraryId,
Guid PluginId,
bool IsEnabled
);
@@ -9,16 +9,10 @@ namespace Lumina.Presentation.Web.Common.Requests.Plugins;
/// <summary>
/// Represents a request to update the settings of a plugin.
/// </summary>
/// <param name="PluginId">The unique identifier of the plugin. Required.</param>
/// <param name="Settings">The settings of the plugin. Optional.</param>
[DebuggerDisplay("PluginId: {PluginId}")]
public class UpdatePluginSettingsRequest
{
/// <summary>
/// Gets or sets the unique identifier of the plugin.
/// </summary>
public Guid PluginId { get; set; }
/// <summary>
/// Gets or sets the settings of the plugin.
/// </summary>
public Dictionary<string, string>? Settings { get; set; }
}
public record UpdatePluginSettingsRequest(
Guid PluginId,
Dictionary<string, string>? Settings
);
@@ -22,12 +22,12 @@ public class ReorderArtworkProvidersEndpointSummary : Summary<ReorderArtworkProv
Summary = "Reorders the artwork providers of a media library.";
Description = "Reorders the artwork providers of the media library identified by the route, in the provided order.";
RequestParam(r => r.LibraryId, "The Id of the media library whose artwork providers are reordered. Required.");
RequestParam(r => r.PluginIds, "The plugin Ids in the new order, from highest to lowest rank. Required.");
ExampleRequest = new ReorderLibraryArtworkProvidersRequest
{
LibraryId = Guid.NewGuid(),
PluginIds = [Guid.NewGuid(), Guid.NewGuid()]
};
ExampleRequest = new ReorderLibraryArtworkProvidersRequest(
LibraryId: Guid.NewGuid(),
PluginIds: [Guid.NewGuid(), Guid.NewGuid()]
);
Response(200, "The artwork providers of the media library are reordered.", example: new SuccessResponse(true));
}
@@ -25,14 +25,14 @@ public class ReorderMetadataProvidersEndpointSummary : Summary<ReorderMetadataPr
RequestParam(r => r.LibraryId, "The Id of the media library whose metadata providers are reordered. Required.");
RequestParam(r => r.PluginIds, "The plugin Ids in the new order, from highest to lowest rank. Required.");
ExampleRequest = new ReorderLibraryMetadataProvidersRequest
{
LibraryId = Guid.NewGuid(),
PluginIds = [
ExampleRequest = new ReorderLibraryMetadataProvidersRequest(
LibraryId: Guid.NewGuid(),
PluginIds:
[
Guid.NewGuid(),
Guid.NewGuid(),
]
};
);
Response(200, "The metadata providers of the media library are reordered.", example: new SuccessResponse(true));
}
@@ -25,12 +25,11 @@ public class SetArtworkProviderEnabledEndpointSummary : Summary<SetArtworkProvid
RequestParam(r => r.PluginId, "The unique identifier of the plugin providing the artwork. Required.");
RequestParam(r => r.IsEnabled, "Whether the artwork provider should be enabled for the media library, or not. Required.");
ExampleRequest = new SetLibraryArtworkProviderEnabledRequest
{
LibraryId = Guid.NewGuid(),
PluginId = Guid.NewGuid(),
IsEnabled = true
};
ExampleRequest = new SetLibraryArtworkProviderEnabledRequest(
LibraryId: Guid.NewGuid(),
PluginId: Guid.NewGuid(),
IsEnabled: true
);
Response(200, "The artwork provider of the media library is enabled or disabled.", example: new SuccessResponse(true));
}
@@ -25,12 +25,11 @@ public class SetBookReaderEnabledEndpointSummary : Summary<SetBookReaderEnabledE
RequestParam(r => r.PluginId, "The unique identifier of the plugin providing the book reader. Required.");
RequestParam(r => r.IsEnabled, "Whether the book reader should be enabled for the media library, or not. Required.");
ExampleRequest = new SetBookReaderEnabledRequest
{
LibraryId = Guid.NewGuid(),
PluginId = Guid.NewGuid(),
IsEnabled = true
};
ExampleRequest = new SetBookReaderEnabledRequest(
LibraryId: Guid.NewGuid(),
PluginId: Guid.NewGuid(),
IsEnabled: true
);
Response(200, "The book reader of the media library is enabled or disabled.", example: new SuccessResponse(true));
}
@@ -25,12 +25,11 @@ public class SetMetadataProviderEnabledEndpointSummary : Summary<SetMetadataProv
RequestParam(r => r.PluginId, "The unique identifier of the plugin providing the metadata. Required.");
RequestParam(r => r.IsEnabled, "Whether the metadata provider should be enabled for the media library, or not. Required.");
ExampleRequest = new SetLibraryMetadataProviderEnabledRequest
{
LibraryId = Guid.NewGuid(),
PluginId = Guid.NewGuid(),
IsEnabled = true
};
ExampleRequest = new SetLibraryMetadataProviderEnabledRequest(
LibraryId: Guid.NewGuid(),
PluginId: Guid.NewGuid(),
IsEnabled: true
);
Response(200, "The metadata provider of the media library is enabled or disabled.", example: new SuccessResponse(true));
}
@@ -33,17 +33,16 @@ public class GetLibraryItemsEndpointSummary : Summary<GetLibraryItemsEndpoint, G
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.");
ExampleRequest = new GetBooksLiteRequest
{
LibraryId = Guid.NewGuid(),
CurrentPage = 1,
PerPage = 48,
SearchTerm = "fellowship",
FilterAlphaKey = "f",
ShouldIgnoreThePrefixForAlphaPicker = true,
SortBy = "title",
SortOrder = SortOrder.Ascending
};
ExampleRequest = new GetBooksLiteRequest(
LibraryId: Guid.NewGuid(),
CurrentPage: 1,
PerPage: 48,
SearchTerm: "fellowship",
FilterAlphaKey: "f",
ShouldIgnoreThePrefixForAlphaPicker: true,
SortBy: "title",
SortOrder: SortOrder.Ascending
);
Response(200, "The lightweight details of the books of the media library are returned.", example: new SuccessResponse<PaginatedBookLiteDto>(true, default));
}
@@ -50,14 +50,15 @@ 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 {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.
// The book is identified by the {bookId} route value, not by the id posted in the body, so that a mismatched id can never redirect
// the update to another book; both ids are normalized to Guids before they are substituted into the upstream URL, so that a crafted
// 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["bookId"]?.ToString() ?? string.Empty;
request.BookId = Guid.TryParse(routeId, out Guid bookId) ? bookId.ToString() : Guid.Empty.ToString();
string bookId = Guid.TryParse(routeId, out Guid parsedBookId) ? parsedBookId.ToString() : Guid.Empty.ToString();
UpdateBookRequest requestWithRouteId = request with { BookId = bookId };
BookDetailsDto book = await _apiHttpClient.PutAsync<BookDetailsDto, UpdateBookRequest>(
ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId), request, cancellationToken).ConfigureAwait(false);
ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", requestWithRouteId.LibraryId.ToString()).Replace("{bookId}", bookId), requestWithRouteId, cancellationToken).ConfigureAwait(false);
return JsonSuccess(book);
}
}
@@ -72,11 +72,10 @@ public class SaveBookEndpointSummary : Summary<SaveBookEndpoint, UpdateBookReque
RequestParam(r => r.Contributors, "The list of media contributors of the book. Required.");
RequestParam(r => r.Ratings, "The list of ratings of the book. Required.");
ExampleRequest = new UpdateBookRequest
{
BookId = Guid.NewGuid().ToString(),
LibraryId = Guid.NewGuid(),
Metadata = new WrittenContentMetadataDto
ExampleRequest = new UpdateBookRequest(
BookId: Guid.NewGuid().ToString(),
LibraryId: Guid.NewGuid(),
Metadata: new WrittenContentMetadataDto
{
Title = "The Fellowship of the Ring",
OriginalTitle = "The Fellowship of the Ring",
@@ -117,28 +116,28 @@ public class SaveBookEndpointSummary : Summary<SaveBookEndpoint, UpdateBookReque
Publisher = "Houghton Mifflin",
PageCount = 398
},
Format = BookFormat.Paperback,
Edition = "50th Anniversary Edition",
VolumeNumber = 1,
Series = new BookSeriesDto
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 =
ASIN: "B007978NPG",
GoodreadsId: "3",
LCCN: "54009621",
OCLCNumber: "ocm00012345",
OpenLibraryId: "OL7603910M",
LibraryThingId: "3203347",
GoogleBooksId: "aWZzLPhY4o0C",
BarnesAndNobleId: "1100307790",
AppleBooksId: "id395211",
ISBNs:
[
new IsbnDto { Value = "0395272238", Format = IsbnFormat.Isbn10 },
new IsbnDto { Value = "9780395272237", Format = IsbnFormat.Isbn13 }
],
Contributors =
Contributors:
[
new MediaContributorDto
{
@@ -151,12 +150,12 @@ public class SaveBookEndpointSummary : Summary<SaveBookEndpoint, UpdateBookReque
Role = MediaContributorRole.Illustrator
}
],
Ratings =
Ratings:
[
new BookRatingDto { Source = BookRatingSource.GoogleBooks, Value = 4.36M, MaxValue = 5, VoteCount = 2345678 },
new BookRatingDto { Source = BookRatingSource.Amazon, Value = 4.7M, MaxValue = 5, VoteCount = 87654 }
]
};
);
Response(200, "The updated book is returned.", example: new SuccessResponse<BookDetailsDto>(true, default));
}
@@ -25,15 +25,14 @@ public class UpdatePluginSettingsEndpointSummary : Summary<UpdatePluginSettingsE
RequestParam(r => r.PluginId, "The unique identifier of the plugin. Required.");
RequestParam(r => r.Settings, "The settings of the plugin. Optional.");
ExampleRequest = new UpdatePluginSettingsRequest
{
PluginId = Guid.NewGuid(),
Settings = new Dictionary<string, string>
ExampleRequest = new UpdatePluginSettingsRequest(
PluginId: Guid.NewGuid(),
Settings: new Dictionary<string, string>
{
{ "preferredLanguage", "fr" },
{ "selectionStrategy", "first" }
}
};
);
Response(200, "The settings of the plugin are updated.", example: new SuccessResponse(true));
}
@@ -10,7 +10,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Libraries;
/// <summary>
/// Fixture class for the <see cref="GetBooksLiteRequest"/> class.
/// Fixture class for the <see cref="GetBooksLiteRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetBooksLiteRequestFixture
@@ -37,17 +37,16 @@ public class GetBooksLiteRequestFixture
string? sortBy = null,
SortOrder? sortOrder = null)
{
return new GetBooksLiteRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
CurrentPage = currentPage,
PerPage = perPage,
SearchTerm = searchTerm,
FilterAlphaKey = filterAlphaKey,
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker,
SortBy = sortBy,
SortOrder = sortOrder
};
return new GetBooksLiteRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
CurrentPage: currentPage,
PerPage: perPage,
SearchTerm: searchTerm,
FilterAlphaKey: filterAlphaKey,
ShouldIgnoreThePrefixForAlphaPicker: shouldIgnoreThePrefixForAlphaPicker,
SortBy: sortBy,
SortOrder: sortOrder
);
}
/// <summary>
@@ -15,7 +15,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Fixture class for the <see cref="UpdateBookRequest"/> class.
/// Fixture class for the <see cref="UpdateBookRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateBookRequestFixture
@@ -73,28 +73,27 @@ public class UpdateBookRequestFixture
bool includeContributors = true,
bool includeRatings = true)
{
return new UpdateBookRequest
{
BookId = id?.ToString() ?? Guid.NewGuid().ToString(),
LibraryId = libraryId ?? Guid.NewGuid(),
Metadata = includeMetadata ? (metadata ?? _writtenContentMetadataDtoFixture.Create()) : null,
Format = includeFormat ? _faker.PickRandom<BookFormat>() : null,
Edition = includeEdition ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
VolumeNumber = includeVolumeNumber ? _faker.Random.Number(1, 3) : null,
Series = includeSeries ? _bookSeriesDtoFixture.Create() : null,
ASIN = includeAsin ? _faker.Random.String2(10) : null,
GoodreadsId = includeGoodreadsId ? _faker.Random.Number(100000, 500000).ToString() : null,
LCCN = includeLccn ? "n78890351" : null,
OCLCNumber = includeOclcNumber ? "ocm12345678" : null,
OpenLibraryId = includeOpenLibraryId ? "OL123456M" : null,
LibraryThingId = includeLibraryThingId ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
GoogleBooksId = includeGoogleBooksId ? CreateGoogleBooksId() : null,
BarnesAndNobleId = includeBarnesAndNobleId ? _faker.Random.String2(10, "0123456789") : null,
AppleBooksId = includeAppleBooksId ? $"id{_faker.Random.Number(1, 999999)}" : null,
ISBNs = includeIsbns ? [.. _isbnDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null,
Contributors = includeContributors ? [.. _mediaContributorDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null,
Ratings = includeRatings ? [.. _bookRatingDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null
};
return new UpdateBookRequest(
BookId: id?.ToString() ?? Guid.NewGuid().ToString(),
LibraryId: libraryId ?? Guid.NewGuid(),
Metadata: includeMetadata ? (metadata ?? _writtenContentMetadataDtoFixture.Create()) : null,
Format: includeFormat ? _faker.PickRandom<BookFormat>() : null,
Edition: includeEdition ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
VolumeNumber: includeVolumeNumber ? _faker.Random.Number(1, 3) : null,
Series: includeSeries ? _bookSeriesDtoFixture.Create() : null,
ASIN: includeAsin ? _faker.Random.String2(10) : null,
GoodreadsId: includeGoodreadsId ? _faker.Random.Number(100000, 500000).ToString() : null,
LCCN: includeLccn ? "n78890351" : null,
OCLCNumber: includeOclcNumber ? "ocm12345678" : null,
OpenLibraryId: includeOpenLibraryId ? "OL123456M" : null,
LibraryThingId: includeLibraryThingId ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
GoogleBooksId: includeGoogleBooksId ? CreateGoogleBooksId() : null,
BarnesAndNobleId: includeBarnesAndNobleId ? _faker.Random.String2(10, "0123456789") : null,
AppleBooksId: includeAppleBooksId ? $"id{_faker.Random.Number(1, 999999)}" : null,
ISBNs: includeIsbns ? [.. _isbnDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null,
Contributors: includeContributors ? [.. _mediaContributorDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null,
Ratings: includeRatings ? [.. _bookRatingDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null
);
}
/// <summary>
@@ -10,7 +10,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="ReorderLibraryArtworkProvidersRequest"/> class.
/// Fixture class for the <see cref="ReorderLibraryArtworkProvidersRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryArtworkProvidersRequestFixture
@@ -27,11 +27,10 @@ public class ReorderLibraryArtworkProvidersRequestFixture
Guid? libraryId = null,
List<Guid>? pluginIds = null)
{
return new ReorderLibraryArtworkProvidersRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginIds = pluginIds ?? [_faker.Random.Guid(), _faker.Random.Guid()]
};
return new ReorderLibraryArtworkProvidersRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
PluginIds: pluginIds ?? [_faker.Random.Guid(), _faker.Random.Guid()]
);
}
/// <summary>
@@ -10,7 +10,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="ReorderLibraryMetadataProvidersRequest"/> class.
/// Fixture class for the <see cref="ReorderLibraryMetadataProvidersRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryMetadataProvidersRequestFixture
@@ -27,11 +27,10 @@ public class ReorderLibraryMetadataProvidersRequestFixture
Guid? libraryId = null,
List<Guid>? pluginIds = null)
{
return new ReorderLibraryMetadataProvidersRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginIds = pluginIds ?? [_faker.Random.Guid(), _faker.Random.Guid()]
};
return new ReorderLibraryMetadataProvidersRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
PluginIds: pluginIds ?? [_faker.Random.Guid(), _faker.Random.Guid()]
);
}
/// <summary>
@@ -9,7 +9,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="SetBookReaderEnabledRequest"/> class.
/// Fixture class for the <see cref="SetBookReaderEnabledRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetBookReaderEnabledRequestFixture
@@ -26,12 +26,11 @@ public class SetBookReaderEnabledRequestFixture
Guid? pluginId = null,
bool? isEnabled = null)
{
return new SetBookReaderEnabledRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginId = pluginId ?? Guid.NewGuid(),
IsEnabled = isEnabled ?? true
};
return new SetBookReaderEnabledRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
PluginId: pluginId ?? Guid.NewGuid(),
IsEnabled: isEnabled ?? true
);
}
/// <summary>
@@ -10,7 +10,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="SetLibraryArtworkProviderEnabledRequest"/> class.
/// Fixture class for the <see cref="SetLibraryArtworkProviderEnabledRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryArtworkProviderEnabledRequestFixture
@@ -29,12 +29,11 @@ public class SetLibraryArtworkProviderEnabledRequestFixture
Guid? pluginId = null,
bool? isEnabled = null)
{
return new SetLibraryArtworkProviderEnabledRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginId = pluginId ?? Guid.NewGuid(),
IsEnabled = isEnabled ?? _faker.Random.Bool()
};
return new SetLibraryArtworkProviderEnabledRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
PluginId: pluginId ?? Guid.NewGuid(),
IsEnabled: isEnabled ?? _faker.Random.Bool()
);
}
/// <summary>
@@ -10,7 +10,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="SetLibraryMetadataProviderEnabledRequest"/> class.
/// Fixture class for the <see cref="SetLibraryMetadataProviderEnabledRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryMetadataProviderEnabledRequestFixture
@@ -29,12 +29,11 @@ public class SetLibraryMetadataProviderEnabledRequestFixture
Guid? pluginId = null,
bool? isEnabled = null)
{
return new SetLibraryMetadataProviderEnabledRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginId = pluginId ?? Guid.NewGuid(),
IsEnabled = isEnabled ?? _faker.Random.Bool()
};
return new SetLibraryMetadataProviderEnabledRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
PluginId: pluginId ?? Guid.NewGuid(),
IsEnabled: isEnabled ?? _faker.Random.Bool()
);
}
/// <summary>
@@ -10,7 +10,7 @@ using System.Linq;
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="UpdatePluginSettingsRequest"/> class.
/// Fixture class for the <see cref="UpdatePluginSettingsRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdatePluginSettingsRequestFixture
@@ -27,11 +27,10 @@ public class UpdatePluginSettingsRequestFixture
Guid? pluginId = null,
Dictionary<string, string>? settings = null)
{
return new UpdatePluginSettingsRequest
{
PluginId = pluginId ?? Guid.NewGuid(),
Settings = settings ?? new Dictionary<string, string> { [_faker.Lorem.Word()] = _faker.Lorem.Word() }
};
return new UpdatePluginSettingsRequest(
PluginId: pluginId ?? Guid.NewGuid(),
Settings: settings ?? new Dictionary<string, string> { [_faker.Lorem.Word()] = _faker.Lorem.Word() }
);
}
/// <summary>
@@ -45,6 +45,7 @@ public class SaveBookEndpointTests
// Arrange
string routeId = Guid.NewGuid().ToString();
UpdateBookRequest request = _updateBookRequestFixture.Create();
string originalBookId = request.BookId!;
BookDetailsDto expectedBook = _bookDetailsDtoFixture.Create();
_mockApiHttpClient.PutAsync<BookDetailsDto, UpdateBookRequest>(Arg.Any<string>(), Arg.Any<UpdateBookRequest>(), Arg.Any<CancellationToken>())
.Returns(expectedBook);
@@ -56,8 +57,9 @@ public class SaveBookEndpointTests
// Assert
await _mockApiHttpClient.Received(1).PutAsync<BookDetailsDto, UpdateBookRequest>(
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", routeId)),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest == request && forwardedRequest.BookId == routeId),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest.BookId == routeId),
Arg.Any<CancellationToken>());
Assert.Equal(originalBookId, request.BookId);
}
[Fact]
@@ -66,8 +68,7 @@ public class SaveBookEndpointTests
// Arrange
string routeId = Guid.NewGuid().ToString();
string bodyId = Guid.NewGuid().ToString();
UpdateBookRequest request = _updateBookRequestFixture.Create();
request.BookId = bodyId;
UpdateBookRequest request = _updateBookRequestFixture.Create() with { BookId = bodyId };
BookDetailsDto expectedBook = _bookDetailsDtoFixture.Create();
_mockApiHttpClient.PutAsync<BookDetailsDto, UpdateBookRequest>(Arg.Any<string>(), Arg.Any<UpdateBookRequest>(), Arg.Any<CancellationToken>())
.Returns(expectedBook);
@@ -79,8 +80,9 @@ public class SaveBookEndpointTests
// Assert
await _mockApiHttpClient.Received(1).PutAsync<BookDetailsDto, UpdateBookRequest>(
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", routeId)),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest == request && forwardedRequest.BookId == routeId && forwardedRequest.BookId != bodyId),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest.BookId == routeId && forwardedRequest.BookId != bodyId),
Arg.Any<CancellationToken>());
Assert.Equal(bodyId, request.BookId);
}
[Fact]
@@ -101,7 +103,7 @@ public class SaveBookEndpointTests
// Assert
await _mockApiHttpClient.Received(1).PutAsync<BookDetailsDto, UpdateBookRequest>(
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", expectedId)),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest == request && forwardedRequest.BookId == expectedId),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest.BookId == expectedId),
Arg.Any<CancellationToken>());
}
@@ -122,7 +124,7 @@ public class SaveBookEndpointTests
// Assert
await _mockApiHttpClient.Received(1).PutAsync<BookDetailsDto, UpdateBookRequest>(
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", expectedId)),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest == request && forwardedRequest.BookId == expectedId),
Arg.Is<UpdateBookRequest>(forwardedRequest => forwardedRequest.BookId == expectedId),
Arg.Any<CancellationToken>());
}
@@ -148,7 +150,7 @@ public class SaveBookEndpointTests
}
/// <summary>
/// Sets the <c>id</c> route value the endpoint reads the book Id from.
/// Sets the <c>bookId</c> route value the endpoint reads the book Id from.
/// </summary>
/// <param name="routeId">The raw route value of the book Id.</param>
private void ConfigureRequest(string routeId)
@@ -157,10 +159,10 @@ public class SaveBookEndpointTests
}
/// <summary>
/// Leaves the <c>id</c> route value unset.
/// Leaves the <c>bookId</c> route value unset.
/// </summary>
private void ConfigureRequestWithoutId()
{
_sut.HttpContext.Request.RouteValues.Remove("id");
_sut.HttpContext.Request.RouteValues.Remove("bookId");
}
}