mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 16: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
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetLibraryMetadataProvidersRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetLibraryMetadataProvidersRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetLibraryMetadataProvidersQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetLibraryMetadataProvidersQuery ToQuery(this GetLibraryMetadataProvidersRequest request)
|
||||
{
|
||||
return new GetLibraryMetadataProvidersQuery(request.LibraryId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetPluginSettingsRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetPluginSettingsRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetPluginSettingsQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetPluginSettingsQuery ToQuery(this GetPluginSettingsRequest request)
|
||||
{
|
||||
return new GetPluginSettingsQuery(request.PluginId);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="LibraryMetadataProviderConfigurationEntity"/>.
|
||||
/// </summary>
|
||||
public static class LibraryMetadataProviderConfigurationEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="configuration"/> to <see cref="LibraryMetadataProviderResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The repository entity to be converted.</param>
|
||||
/// <param name="providerName">The display name of the metadata provider.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static LibraryMetadataProviderResponse ToResponse(this LibraryMetadataProviderConfigurationEntity configuration, string providerName)
|
||||
{
|
||||
return new LibraryMetadataProviderResponse(
|
||||
configuration.PluginId,
|
||||
providerName,
|
||||
configuration.IsEnabled,
|
||||
configuration.Rank
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PluginEntity"/>.
|
||||
/// </summary>
|
||||
public static class PluginEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="pluginEntity"/> to <see cref="PluginResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="pluginEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static PluginResponse ToResponse(this PluginEntity pluginEntity)
|
||||
{
|
||||
return new PluginResponse(
|
||||
pluginEntity.Id,
|
||||
pluginEntity.Name,
|
||||
pluginEntity.Author,
|
||||
pluginEntity.Version,
|
||||
pluginEntity.Description,
|
||||
pluginEntity.LoadStatus,
|
||||
pluginEntity.LoadError,
|
||||
pluginEntity.ToSettings()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the settings of <paramref name="pluginEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="pluginEntity">The repository entity whose settings are deserialized.</param>
|
||||
/// <returns>The deserialized settings, or <see langword="null"/> when no settings are stored.</returns>
|
||||
public static IReadOnlyDictionary<string, string>? ToSettings(this PluginEntity pluginEntity)
|
||||
{
|
||||
if (pluginEntity.SettingsJson is null)
|
||||
return null;
|
||||
return JsonSerializer.Deserialize<Dictionary<string, string>>(pluginEntity.SettingsJson);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||
using ContractsPluginSettingType = Lumina.Contracts.Responses.Plugins.PluginSettingType;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PluginSettingDescriptorDto"/>.
|
||||
/// </summary>
|
||||
public static class PluginSettingDescriptorMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="descriptor"/> to <see cref="PluginSettingDescriptorResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="descriptor">The plugin contract setting descriptor to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static PluginSettingDescriptorResponse ToResponse(this PluginSettingDescriptorDto descriptor)
|
||||
{
|
||||
return new PluginSettingDescriptorResponse(
|
||||
descriptor.Key,
|
||||
descriptor.Label,
|
||||
(ContractsPluginSettingType)(int)descriptor.Type,
|
||||
descriptor.DefaultValue,
|
||||
descriptor.AllowedValues
|
||||
);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ReorderLibraryMetadataProvidersRequest"/>.
|
||||
/// </summary>
|
||||
public static class ReorderLibraryMetadataProvidersRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="ReorderLibraryMetadataProvidersCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static ReorderLibraryMetadataProvidersCommand ToCommand(this ReorderLibraryMetadataProvidersRequest request)
|
||||
{
|
||||
return new ReorderLibraryMetadataProvidersCommand(request.LibraryId, request.PluginIds);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="SetLibraryMetadataProviderEnabledRequest"/>.
|
||||
/// </summary>
|
||||
public static class SetLibraryMetadataProviderEnabledRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="SetLibraryMetadataProviderEnabledCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static SetLibraryMetadataProviderEnabledCommand ToCommand(this SetLibraryMetadataProviderEnabledRequest request)
|
||||
{
|
||||
return new SetLibraryMetadataProviderEnabledCommand(request.LibraryId, request.PluginId, request.IsEnabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="UpdatePluginSettingsRequest"/>.
|
||||
/// </summary>
|
||||
public static class UpdatePluginSettingsRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="UpdatePluginSettingsCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static UpdatePluginSettingsCommand ToCommand(this UpdatePluginSettingsRequest request)
|
||||
{
|
||||
return new UpdatePluginSettingsCommand(request.PluginId, request.Settings);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Command for reordering the metadata providers of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose metadata providers are reordered.</param>
|
||||
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank.</param>
|
||||
public record ReorderLibraryMetadataProvidersCommand(
|
||||
Guid LibraryId,
|
||||
IReadOnlyList<Guid> PluginIds
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to reorder the metadata providers of a media library.
|
||||
/// </summary>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandler : IRequestHandler<ReorderLibraryMetadataProvidersCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public ReorderLibraryMetadataProvidersCommandHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to reorder the metadata providers of a media library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<Success>> Handle(ReorderLibraryMetadataProvidersCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(request.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
Dictionary<Guid, LibraryMetadataProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
||||
for (int rank = 0; rank < request.PluginIds.Count; rank++)
|
||||
{
|
||||
Guid pluginId = request.PluginIds[rank];
|
||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? configuration))
|
||||
{
|
||||
configuration.Rank = rank + 1;
|
||||
ErrorOr<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsError)
|
||||
return upsertResult.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="ReorderLibraryMetadataProvidersCommand"/>.
|
||||
/// </summary>
|
||||
public class ReorderLibraryMetadataProvidersCommandValidator : AbstractValidator<ReorderLibraryMetadataProvidersCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public ReorderLibraryMetadataProvidersCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.LibraryId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.LibraryIdCannotBeEmpty.Description);
|
||||
RuleFor(x => x.PluginIds)
|
||||
.NotNull().WithMessage(Errors.Plugins.PluginIdsListCannotBeNull.Description)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.PluginIdsListCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Command for enabling or disabling a metadata provider for a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose metadata provider is enabled or disabled.</param>
|
||||
/// <param name="PluginId">The unique identifier of the plugin providing the metadata.</param>
|
||||
/// <param name="IsEnabled">Whether the metadata provider should be enabled for the media library.</param>
|
||||
public record SetLibraryMetadataProviderEnabledCommand(
|
||||
Guid LibraryId,
|
||||
Guid PluginId,
|
||||
bool IsEnabled
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to enable or disable a metadata provider for a media library.
|
||||
/// </summary>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandler : IRequestHandler<SetLibraryMetadataProviderEnabledCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public SetLibraryMetadataProviderEnabledCommandHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to enable or disable a metadata provider for a media library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<Success>> Handle(SetLibraryMetadataProviderEnabledCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await configurationRepository.GetByLibraryAndPluginIdAsync(request.LibraryId, request.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsError)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
LibraryMetadataProviderConfigurationEntity configuration;
|
||||
if (getConfigurationResult.Value is not null)
|
||||
{
|
||||
configuration = getConfigurationResult.Value;
|
||||
configuration.IsEnabled = request.IsEnabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
// compute the rank to assign to the new configuration, appending it after the existing ones
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(request.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
return getConfigurationsResult.Errors;
|
||||
int nextRank = getConfigurationsResult.Value.Count == 0 ? 1 : getConfigurationsResult.Value.Max(configuration => configuration.Rank) + 1;
|
||||
configuration = new LibraryMetadataProviderConfigurationEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = request.LibraryId,
|
||||
PluginId = request.PluginId,
|
||||
IsEnabled = request.IsEnabled,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
|
||||
ErrorOr<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsError)
|
||||
return upsertResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="SetLibraryMetadataProviderEnabledCommand"/>.
|
||||
/// </summary>
|
||||
public class SetLibraryMetadataProviderEnabledCommandValidator : AbstractValidator<SetLibraryMetadataProviderEnabledCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public SetLibraryMetadataProviderEnabledCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.LibraryId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.LibraryIdCannotBeEmpty.Description);
|
||||
RuleFor(x => x.PluginId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.PluginIdCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Command for updating the settings of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The unique identifier of the plugin.</param>
|
||||
/// <param name="Settings">The settings of the plugin.</param>
|
||||
public record UpdatePluginSettingsCommand(
|
||||
Guid PluginId,
|
||||
IReadOnlyDictionary<string, string>? Settings
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Mediator;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to update the settings of a plugin.
|
||||
/// </summary>
|
||||
public class UpdatePluginSettingsCommandHandler : IRequestHandler<UpdatePluginSettingsCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdatePluginSettingsCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public UpdatePluginSettingsCommandHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to update the settings of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<Success>> Handle(UpdatePluginSettingsCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
string? settingsJson = request.Settings is not null ? JsonSerializer.Serialize(request.Settings) : null;
|
||||
ErrorOr<Updated> updateResult = await pluginRepository.UpdateSettingsAsync(request.PluginId, settingsJson, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsError)
|
||||
return updateResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="UpdatePluginSettingsCommand"/>.
|
||||
/// </summary>
|
||||
public class UpdatePluginSettingsCommandValidator : AbstractValidator<UpdatePluginSettingsCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdatePluginSettingsCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public UpdatePluginSettingsCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.PluginId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.PluginIdCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the metadata providers configured for a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose metadata providers are retrieved.</param>
|
||||
public record GetLibraryMetadataProvidersQuery(
|
||||
Guid LibraryId
|
||||
) : IRequest<ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>>;
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the metadata providers configured for a media library.
|
||||
/// </summary>
|
||||
public class GetLibraryMetadataProvidersQueryHandler : IRequestHandler<GetLibraryMetadataProvidersQuery, ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryMetadataProvidersQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public GetLibraryMetadataProvidersQueryHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the metadata providers configured for a media library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>> Handle(GetLibraryMetadataProvidersQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(request.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
// build a plugin name lookup from the detected plugins
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsError)
|
||||
return getPluginsResult.Errors;
|
||||
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||
|
||||
return getConfigurationsResult.Value
|
||||
.OrderBy(configuration => configuration.Rank)
|
||||
.Select(configuration => configuration.ToResponse(pluginNames.GetValueOrDefault(configuration.PluginId) ?? string.Empty))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the settings of a plugin and their schema.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The unique identifier of the plugin.</param>
|
||||
public record GetPluginSettingsQuery(
|
||||
Guid PluginId
|
||||
) : IRequest<ErrorOr<PluginSettingsResponse>>;
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the settings of a plugin and their schema.
|
||||
/// </summary>
|
||||
public class GetPluginSettingsQueryHandler : IRequestHandler<GetPluginSettingsQuery, ErrorOr<PluginSettingsResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPluginSettingsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="pluginManager">Injected manager of the plugins loaded by the host application.</param>
|
||||
public GetPluginSettingsQueryHandler(IUnitOfWork unitOfWork, IPluginManager pluginManager)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the settings of a plugin and their schema.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a <see cref="PluginSettingsResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<PluginSettingsResponse>> Handle(GetPluginSettingsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(request.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsError)
|
||||
return getPluginResult.Errors;
|
||||
PluginEntity? pluginEntity = getPluginResult.Value;
|
||||
if (pluginEntity is null)
|
||||
return Errors.Plugins.PluginNotFound;
|
||||
|
||||
// the schema comes from the loaded plugin, the current values from the storage medium
|
||||
IPlugin? loadedPlugin = _pluginManager.GetPlugin(request.PluginId);
|
||||
IReadOnlyList<PluginSettingDescriptorResponse> schema = loadedPlugin is not null
|
||||
? loadedPlugin.GetSettingsSchema().Select(setting => setting.ToResponse()).ToList()
|
||||
: [];
|
||||
return new PluginSettingsResponse(request.PluginId, schema, pluginEntity.ToSettings());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting all the detected plugins.
|
||||
/// </summary>
|
||||
public record GetPluginsQuery() : IRequest<ErrorOr<IReadOnlyList<PluginResponse>>>;
|
||||
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all the detected plugins.
|
||||
/// </summary>
|
||||
public class GetPluginsQueryHandler : IRequestHandler<GetPluginsQuery, ErrorOr<IReadOnlyList<PluginResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPluginsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public GetPluginsQueryHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get all the detected plugins.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="PluginResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<IReadOnlyList<PluginResponse>>> Handle(GetPluginsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getPluginsResult.Match(
|
||||
plugins => ErrorOrFactory.From<IReadOnlyList<PluginResponse>>(plugins.Select(plugin => plugin.ToResponse()).ToList()),
|
||||
errors => errors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to get the metadata providers configured for a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose metadata providers are retrieved. Required.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public sealed record GetLibraryMetadataProvidersRequest(
|
||||
Guid LibraryId
|
||||
);
|
||||
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to get the settings of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The unique identifier of the plugin. Required.</param>
|
||||
[DebuggerDisplay("PluginId: {PluginId}")]
|
||||
public sealed record GetPluginSettingsRequest(
|
||||
Guid PluginId
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.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 sealed record ReorderLibraryMetadataProvidersRequest(
|
||||
Guid LibraryId,
|
||||
IReadOnlyList<Guid> PluginIds
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.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.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
|
||||
public sealed record SetLibraryMetadataProviderEnabledRequest(
|
||||
Guid LibraryId,
|
||||
Guid PluginId,
|
||||
bool IsEnabled
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.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.</param>
|
||||
[DebuggerDisplay("PluginId: {PluginId}")]
|
||||
public sealed record UpdatePluginSettingsRequest(
|
||||
Guid PluginId,
|
||||
IReadOnlyDictionary<string, string>? Settings
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a metadata provider configured for a media library.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The unique identifier of the plugin providing the metadata.</param>
|
||||
/// <param name="Name">The display name of the metadata provider.</param>
|
||||
/// <param name="IsEnabled">Whether the metadata provider is enabled for the media library.</param>
|
||||
/// <param name="Rank">The rank of the metadata provider, determining the order in which providers are tried.</param>
|
||||
public sealed record LibraryMetadataProviderResponse(
|
||||
Guid PluginId,
|
||||
string Name,
|
||||
bool IsEnabled,
|
||||
int Rank
|
||||
);
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a detected plugin.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the plugin.</param>
|
||||
/// <param name="Name">The display name of the plugin.</param>
|
||||
/// <param name="Author">The author of the plugin.</param>
|
||||
/// <param name="Version">The version of the plugin.</param>
|
||||
/// <param name="Description">The description of the plugin.</param>
|
||||
/// <param name="LoadStatus">The load status of the plugin.</param>
|
||||
/// <param name="LoadError">The error message when the plugin failed to load, if applicable.</param>
|
||||
/// <param name="Settings">The settings of the plugin.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public sealed record PluginResponse(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string Author,
|
||||
string Version,
|
||||
string Description,
|
||||
PluginLoadStatus LoadStatus,
|
||||
string? LoadError,
|
||||
IReadOnlyDictionary<string, string>? Settings
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a single setting of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="Key">The unique key of the setting.</param>
|
||||
/// <param name="Label">The display label of the setting.</param>
|
||||
/// <param name="Type">The type of the setting.</param>
|
||||
/// <param name="DefaultValue">The optional default value of the setting.</param>
|
||||
/// <param name="AllowedValues">The list of allowed values, when the setting is a selection.</param>
|
||||
public sealed record PluginSettingDescriptorResponse(
|
||||
string Key,
|
||||
string Label,
|
||||
PluginSettingType Type,
|
||||
string? DefaultValue,
|
||||
IReadOnlyList<string>? AllowedValues
|
||||
);
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Lumina.Contracts.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the types of a plugin setting.
|
||||
/// </summary>
|
||||
public enum PluginSettingType
|
||||
{
|
||||
/// <summary>
|
||||
/// A free-form single line text value.
|
||||
/// </summary>
|
||||
Text,
|
||||
|
||||
/// <summary>
|
||||
/// A numeric value.
|
||||
/// </summary>
|
||||
Number,
|
||||
|
||||
/// <summary>
|
||||
/// A boolean (true/false) value.
|
||||
/// </summary>
|
||||
Boolean,
|
||||
|
||||
/// <summary>
|
||||
/// A value selected from a list of allowed values.
|
||||
/// </summary>
|
||||
Select
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the settings of a plugin and their schema.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The unique identifier of the plugin.</param>
|
||||
/// <param name="Schema">The schema of the plugin settings.</param>
|
||||
/// <param name="Settings">The current values of the plugin settings.</param>
|
||||
public sealed record PluginSettingsResponse(
|
||||
Guid PluginId,
|
||||
IReadOnlyList<PluginSettingDescriptorResponse> Schema,
|
||||
IReadOnlyDictionary<string, string>? Settings
|
||||
);
|
||||
@@ -22,5 +22,8 @@ public static partial class ApiRoutes
|
||||
public const string GET_RUNNING_LIBRARIES_SCAN = "/libraries/scans/running";
|
||||
public const string CANCEL_LIBRARIES_SCAN = "/libraries/scans/cancel";
|
||||
public const string CANCEL_LIBRARY_SCAN = "/libraries/{libraryId}/scans/{scanId}/cancel";
|
||||
public const string GET_LIBRARY_METADATA_PROVIDERS = "/libraries/{libraryId}/metadata-providers";
|
||||
public const string SET_LIBRARY_METADATA_PROVIDER_ENABLED = "/libraries/{libraryId}/metadata-providers/{pluginId}/enabled";
|
||||
public const string REORDER_LIBRARY_METADATA_PROVIDERS = "/libraries/{libraryId}/metadata-providers/reorder";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Lumina.Presentation.Api.Common.Routes.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of routes defined in this API.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the Plugins route.
|
||||
/// </summary>
|
||||
public static class Plugins
|
||||
{
|
||||
public const string GET_PLUGINS = "/plugins";
|
||||
public const string GET_PLUGIN_SETTINGS = "/plugins/{pluginId}/settings";
|
||||
public const string UPDATE_PLUGIN_SETTINGS = "/plugins/{pluginId}/settings";
|
||||
}
|
||||
}
|
||||
+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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+54
@@ -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);
|
||||
}
|
||||
}
|
||||
+138
@@ -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);
|
||||
}
|
||||
}
|
||||
+97
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -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);
|
||||
}
|
||||
}
|
||||
+116
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -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);
|
||||
}
|
||||
}
|
||||
+113
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -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);
|
||||
}
|
||||
}
|
||||
+114
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ReorderLibraryMetadataProvidersCommandHandler"/> class.
|
||||
/// </summary>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandlerTests
|
||||
{
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly ILibraryMetadataProviderConfigurationRepository _mockConfigurationRepository;
|
||||
private readonly ReorderLibraryMetadataProvidersCommandHandler _sut;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersCommandHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public ReorderLibraryMetadataProvidersCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>().Returns(_mockConfigurationRepository);
|
||||
_sut = new ReorderLibraryMetadataProvidersCommandHandler(_mockUnitOfWork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalled_ShouldAssignRanksInTheProvidedOrder()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
LibraryMetadataProviderConfigurationEntity firstProvider = CreateConfiguration(libraryId, Guid.NewGuid(), 2);
|
||||
LibraryMetadataProviderConfigurationEntity secondProvider = CreateConfiguration(libraryId, Guid.NewGuid(), 1);
|
||||
_mockConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<LibraryMetadataProviderConfigurationEntity> { firstProvider, secondProvider });
|
||||
_mockConfigurationRepository.UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new ReorderLibraryMetadataProvidersCommand(libraryId, [secondProvider.PluginId, firstProvider.PluginId]), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
await _mockConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == secondProvider.PluginId && configuration.Rank == 1),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == firstProvider.PluginId && configuration.Rank == 2),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
private static LibraryMetadataProviderConfigurationEntity CreateConfiguration(Guid libraryId, Guid pluginId, int rank)
|
||||
{
|
||||
return new LibraryMetadataProviderConfigurationEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = libraryId,
|
||||
PluginId = pluginId,
|
||||
IsEnabled = true,
|
||||
Rank = rank,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SetLibraryMetadataProviderEnabledCommandHandler"/> class.
|
||||
/// </summary>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandlerTests
|
||||
{
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly ILibraryMetadataProviderConfigurationRepository _mockConfigurationRepository;
|
||||
private readonly SetLibraryMetadataProviderEnabledCommandHandler _sut;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledCommandHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public SetLibraryMetadataProviderEnabledCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>().Returns(_mockConfigurationRepository);
|
||||
_sut = new SetLibraryMetadataProviderEnabledCommandHandler(_mockUnitOfWork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenConfigurationDoesNotExist_ShouldCreateEnabledConfigurationWithNextRank()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
_mockConfigurationRepository.GetByLibraryAndPluginIdAsync(libraryId, pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns((LibraryMetadataProviderConfigurationEntity?)null);
|
||||
_mockConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<LibraryMetadataProviderConfigurationEntity>());
|
||||
_mockConfigurationRepository.UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new SetLibraryMetadataProviderEnabledCommand(libraryId, pluginId, true), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
await _mockConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.IsEnabled && configuration.Rank == 1),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenConfigurationExists_ShouldUpdateItsEnabledState()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity existingConfiguration = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = Guid.NewGuid(),
|
||||
PluginId = Guid.NewGuid(),
|
||||
IsEnabled = false,
|
||||
Rank = 2,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
_mockConfigurationRepository.GetByLibraryAndPluginIdAsync(existingConfiguration.LibraryId, existingConfiguration.PluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(existingConfiguration);
|
||||
_mockConfigurationRepository.UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new SetLibraryMetadataProviderEnabledCommand(existingConfiguration.LibraryId, existingConfiguration.PluginId, true), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
await _mockConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.IsEnabled && configuration.Rank == 2),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UpdatePluginSettingsCommandHandler"/> class.
|
||||
/// </summary>
|
||||
public class UpdatePluginSettingsCommandHandlerTests
|
||||
{
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly IPluginRepository _mockPluginRepository;
|
||||
private readonly UpdatePluginSettingsCommandHandler _sut;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdatePluginSettingsCommandHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public UpdatePluginSettingsCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.GetRepository<IPluginRepository>().Returns(_mockPluginRepository);
|
||||
_sut = new UpdatePluginSettingsCommandHandler(_mockUnitOfWork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalled_ShouldPersistTheSettings()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
Dictionary<string, string> settings = new() { ["preferredLanguage"] = "fr" };
|
||||
_mockPluginRepository.UpdateSettingsAsync(pluginId, Arg.Any<string?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new UpdatePluginSettingsCommand(pluginId, settings), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
await _mockPluginRepository.Received(1).UpdateSettingsAsync(pluginId, Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.Plugins.Queries.GetPlugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPluginsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
public class GetPluginsQueryHandlerTests
|
||||
{
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly IPluginRepository _mockPluginRepository;
|
||||
private readonly GetPluginsQueryHandler _sut;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPluginsQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetPluginsQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.GetRepository<IPluginRepository>().Returns(_mockPluginRepository);
|
||||
_sut = new GetPluginsQueryHandler(_mockUnitOfWork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalled_ShouldReturnAllDetectedPlugins()
|
||||
{
|
||||
// Arrange
|
||||
List<PluginEntity> plugins = [CreatePluginEntity(), CreatePluginEntity()];
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
|
||||
// Act
|
||||
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.Handle(new GetPluginsQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.Equal(2, result.Value.Count);
|
||||
Assert.Equal(plugins[0].Name, result.Value[0].Name);
|
||||
Assert.Equal(plugins[0].Id, result.Value[0].Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenRepositoryReturnsError_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
|
||||
// Act
|
||||
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.Handle(new GetPluginsQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
}
|
||||
|
||||
private static PluginEntity CreatePluginEntity()
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "Test Plugin",
|
||||
Author = "Lumina",
|
||||
Version = "1.0.0",
|
||||
Description = "A test plugin.",
|
||||
LoadStatus = PluginLoadStatus.Loaded,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user