mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Adds the plugins and metadata provider management API
This commit is contained in:
1 parent
6f501a51f3
commit
7d417c1710
51 files changed
+2294
No files matched your search
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/metadata-providers</c> route.
|
||||
/// </summary>
|
||||
public class GetLibraryMetadataProvidersEndpoint : BaseEndpoint<GetLibraryMetadataProvidersRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryMetadataProvidersEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetLibraryMetadataProvidersEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Libraries.GET_LIBRARY_METADATA_PROVIDERS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the metadata providers configured for the media library identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the media library whose metadata providers are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetLibraryMetadataProvidersRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetLibraryMetadataProvidersEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryMetadataProvidersEndpointSummary : Summary<GetLibraryMetadataProvidersEndpoint, GetLibraryMetadataProvidersRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryMetadataProvidersEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetLibraryMetadataProvidersEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the metadata providers configured for a media library.";
|
||||
Description = "Retrieves the metadata providers configured for a media library, with their enabled state and rank.";
|
||||
|
||||
ExampleRequest = new GetLibraryMetadataProvidersRequest(
|
||||
LibraryId: Guid.NewGuid()
|
||||
);
|
||||
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library whose metadata providers are retrieved. Required.");
|
||||
|
||||
ResponseParam<LibraryMetadataProviderResponse>(r => r.PluginId, "The unique identifier of the plugin providing the metadata.");
|
||||
ResponseParam<LibraryMetadataProviderResponse>(r => r.Name, "The display name of the metadata provider.");
|
||||
ResponseParam<LibraryMetadataProviderResponse>(r => r.IsEnabled, "Whether the metadata provider is enabled for the media library.");
|
||||
ResponseParam<LibraryMetadataProviderResponse>(r => r.Rank, "The rank of the metadata provider, determining the order in which providers are tried.");
|
||||
|
||||
Response(200, "The metadata providers configured for the media library are returned.",
|
||||
example: new LibraryMetadataProviderResponse[] {
|
||||
new(
|
||||
PluginId: Guid.NewGuid(),
|
||||
Name: "Goodreads",
|
||||
IsEnabled: true,
|
||||
Rank: 1
|
||||
),
|
||||
new(
|
||||
PluginId: Guid.NewGuid(),
|
||||
Name: "OpenLibrary",
|
||||
IsEnabled: false,
|
||||
Rank: 2
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers"
|
||||
},
|
||||
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/libraries/{libraryId}/metadata-providers"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested media library does not exist.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "LibraryNotFound",
|
||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user