Adds the plugins and metadata provider management API

This commit is contained in:
BinaryAlley committed 2026-08-12 11:05:53 -07:00
1 parent 6f501a51f3
commit 7d417c1710
51 files changed
+2294

No files matched your search

@@ -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);
}
}
@@ -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"
}
);
}
}
@@ -0,0 +1,54 @@
#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.Plugins;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetPluginSettings;
/// <summary>
/// API endpoint for the <c>/plugins/{pluginId}/settings</c> route.
/// </summary>
public class GetPluginSettingsEndpoint : BaseEndpoint<GetPluginSettingsRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="GetPluginSettingsEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public GetPluginSettingsEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Plugins.GET_PLUGIN_SETTINGS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the settings of the plugin identified by <paramref name="request"/> and their schema.
/// </summary>
/// <param name="request">The request containing the Id of the plugin whose settings are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetPluginSettingsRequest request, CancellationToken cancellationToken)
{
ErrorOr<PluginSettingsResponse> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,138 @@
#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.GetPluginSettings;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetPluginSettingsEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPluginSettingsEndpointSummary : Summary<GetPluginSettingsEndpoint, GetPluginSettingsRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetPluginSettingsEndpointSummary"/> class.
/// </summary>
public GetPluginSettingsEndpointSummary()
{
Summary = "Retrieves the settings of a plugin and their schema.";
Description = "Retrieves the settings of a plugin and their schema, used to render the plugin settings page.";
ExampleRequest = new GetPluginSettingsRequest(
PluginId: Guid.NewGuid()
);
RequestParam(r => r.PluginId, "The unique identifier of the plugin. Required.");
ResponseParam<PluginSettingsResponse>(r => r.PluginId, "The unique identifier of the plugin.");
ResponseParam<PluginSettingsResponse>(r => r.Schema, "The schema of the plugin settings, used to render the settings form.");
ResponseParam<PluginSettingsResponse>(r => r.Settings, "The current values of the plugin settings.");
Response(200, "The settings of the plugin and their schema are returned.", example: new PluginSettingsResponse(
PluginId: Guid.NewGuid(),
Schema:
[
new PluginSettingDescriptorResponse(
Key: "preferredLanguage",
Label: "Preferred Language",
Type: PluginSettingType.Text,
DefaultValue: "en",
AllowedValues: null
),
new PluginSettingDescriptorResponse(
Key: "selectionStrategy",
Label: "Selection Strategy",
Type: PluginSettingType.Select,
DefaultValue: "first",
AllowedValues: ["first", "best"]
)
],
Settings: new Dictionary<string, string>
{
{ "preferredLanguage", "fr" },
{ "selectionStrategy", "first" }
}
));
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/plugins/{pluginId}/settings"
},
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/plugins/{pluginId}/settings"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/plugins/{pluginId}/settings"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin.", "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/plugins/{pluginId}/settings",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested plugin 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 = "PluginNotFound",
instance = "/api/v1/plugins/{pluginId}/settings",
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/plugins/{pluginId}/settings",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"PluginIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Core.Plugins.Queries.GetPlugins;
using Lumina.Contracts.Responses.Plugins;
using Lumina.Presentation.Api.Common.Routes.Plugins;
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.GetPlugins;
/// <summary>
/// API endpoint for the <c>/plugins</c> route.
/// </summary>
public class GetPluginsEndpoint : BaseEndpoint<EmptyRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="GetPluginsEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public GetPluginsEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Plugins.GET_PLUGINS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the list of all the detected plugins.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
{
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sender.Send(new GetPluginsQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,97 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Responses.Plugins;
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetPlugins;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetPluginsEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPluginsEndpointSummary : Summary<GetPluginsEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetPluginsEndpointSummary"/> class.
/// </summary>
public GetPluginsEndpointSummary()
{
Summary = "Retrieves the list of detected plugins.";
Description = "Retrieves the list of all the plugins detected by the host application, including their load status and settings.";
ResponseParam<PluginResponse>(r => r.Id, "The unique identifier of the plugin.");
ResponseParam<PluginResponse>(r => r.Name, "The display name of the plugin.");
ResponseParam<PluginResponse>(r => r.Author, "The author of the plugin.");
ResponseParam<PluginResponse>(r => r.Version, "The version of the plugin.");
ResponseParam<PluginResponse>(r => r.Description, "The description of the plugin.");
ResponseParam<PluginResponse>(r => r.LoadStatus, "The load status of the plugin.");
ResponseParam<PluginResponse>(r => r.LoadError, "The error message when the plugin failed to load, if applicable.");
ResponseParam<PluginResponse>(r => r.Settings, "The settings of the plugin.");
Response(200, "The list of detected plugins is returned.",
example: new PluginResponse[] {
new(
Id: Guid.NewGuid(),
Name: "Goodreads",
Author: "Lumina",
Version: "1.0.0",
Description: "Provides book metadata from Goodreads.",
LoadStatus: PluginLoadStatus.Loaded,
LoadError: null,
Settings: new Dictionary<string, string>
{
{ "preferredLanguage", "en" },
{ "selectionStrategy", "first" }
}
)
}
);
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/plugins"
},
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/plugins"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/plugins"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin.", "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/plugins",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Presentation.Api.Common.Routes.Library.Management;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryMetadataProviders;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/metadata-providers/reorder</c> route.
/// </summary>
public class ReorderLibraryMetadataProvidersEndpoint : BaseEndpoint<ReorderLibraryMetadataProvidersRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public ReorderLibraryMetadataProvidersEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.PUT);
Routes(ApiRoutes.Libraries.REORDER_LIBRARY_METADATA_PROVIDERS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Reorders the metadata providers of the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library and the plugin Ids in the new order.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(ReorderLibraryMetadataProvidersRequest request, CancellationToken cancellationToken)
{
ErrorOr<Success> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,116 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryMetadataProviders;
/// <summary>
/// Class used for providing a textual description for the <see cref="ReorderLibraryMetadataProvidersEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryMetadataProvidersEndpointSummary : Summary<ReorderLibraryMetadataProvidersEndpoint, ReorderLibraryMetadataProvidersRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersEndpointSummary"/> class.
/// </summary>
public ReorderLibraryMetadataProvidersEndpointSummary()
{
Summary = "Reorders the metadata providers of a media library.";
Description = "Reorders the metadata providers of a media library, determining the order in which the providers are tried during the metadata enrichment of the library scans.";
ExampleRequest = new ReorderLibraryMetadataProvidersRequest(
LibraryId: Guid.NewGuid(),
PluginIds:
[
Guid.NewGuid(),
Guid.NewGuid()
]
);
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.");
Response(200, "The metadata providers of the media library were successfully reordered.");
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/reorder"
},
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/reorder"
},
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/reorder"
}
}
);
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/reorder",
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/reorder",
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/reorder",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"PluginIdsListCannotBeNull",
"PluginIdsListCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Presentation.Api.Common.Routes.Library.Management;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.SetLibraryMetadataProviderEnabled;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/metadata-providers/{pluginId}/enabled</c> route.
/// </summary>
public class SetLibraryMetadataProviderEnabledEndpoint : BaseEndpoint<SetLibraryMetadataProviderEnabledRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public SetLibraryMetadataProviderEnabledEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.PUT);
Routes(ApiRoutes.Libraries.SET_LIBRARY_METADATA_PROVIDER_ENABLED);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Enables or disables the metadata provider identified by <paramref name="request"/> for the media library.
/// </summary>
/// <param name="request">The request containing the Ids of the media library and of the metadata provider.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(SetLibraryMetadataProviderEnabledRequest request, CancellationToken cancellationToken)
{
ErrorOr<Success> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,113 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.SetLibraryMetadataProviderEnabled;
/// <summary>
/// Class used for providing a textual description for the <see cref="SetLibraryMetadataProviderEnabledEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryMetadataProviderEnabledEndpointSummary : Summary<SetLibraryMetadataProviderEnabledEndpoint, SetLibraryMetadataProviderEnabledRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledEndpointSummary"/> class.
/// </summary>
public SetLibraryMetadataProviderEnabledEndpointSummary()
{
Summary = "Enables or disables a metadata provider for a media library.";
Description = "Enables or disables the metadata provider for the media library, so that it is included or excluded from the metadata enrichment of the library scans.";
ExampleRequest = new SetLibraryMetadataProviderEnabledRequest(
LibraryId: Guid.NewGuid(),
PluginId: Guid.NewGuid(),
IsEnabled: true
);
RequestParam(r => r.LibraryId, "The Id of the media library whose metadata provider is enabled or disabled. Required.");
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. Required.");
Response(200, "The metadata provider was successfully enabled or disabled for the media library.");
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/{pluginId}/enabled"
},
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/{pluginId}/enabled"
},
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/{pluginId}/enabled"
}
}
);
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/{pluginId}/enabled",
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/{pluginId}/enabled",
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/{pluginId}/enabled",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"PluginIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Presentation.Api.Common.Routes.Plugins;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.UpdatePluginSettings;
/// <summary>
/// API endpoint for the <c>/plugins/{pluginId}/settings</c> route.
/// </summary>
public class UpdatePluginSettingsEndpoint : BaseEndpoint<UpdatePluginSettingsRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="UpdatePluginSettingsEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public UpdatePluginSettingsEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.PUT);
Routes(ApiRoutes.Plugins.UPDATE_PLUGIN_SETTINGS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Updates the settings of the plugin identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the plugin and its settings.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(UpdatePluginSettingsRequest request, CancellationToken cancellationToken)
{
ErrorOr<Success> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,114 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.UpdatePluginSettings;
/// <summary>
/// Class used for providing a textual description for the <see cref="UpdatePluginSettingsEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdatePluginSettingsEndpointSummary : Summary<UpdatePluginSettingsEndpoint, UpdatePluginSettingsRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="UpdatePluginSettingsEndpointSummary"/> class.
/// </summary>
public UpdatePluginSettingsEndpointSummary()
{
Summary = "Updates the settings of a plugin.";
Description = "Updates the settings of a plugin, used by the plugin settings page.";
ExampleRequest = new UpdatePluginSettingsRequest(
PluginId: Guid.NewGuid(),
Settings: new Dictionary<string, string>
{
{ "preferredLanguage", "fr" },
{ "selectionStrategy", "first" }
}
);
RequestParam(r => r.PluginId, "The unique identifier of the plugin. Required.");
RequestParam(r => r.Settings, "The settings of the plugin. Required.");
Response(200, "The settings of the plugin were successfully updated.");
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/plugins/{pluginId}/settings"
},
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/plugins/{pluginId}/settings"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/plugins/{pluginId}/settings"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin.", "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/plugins/{pluginId}/settings",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested plugin 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 = "PluginNotFound",
instance = "/api/v1/plugins/{pluginId}/settings",
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/plugins/{pluginId}/settings",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"PluginIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}