mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Replaces FluentValidation and Mediator command/queries handling with custom implementations.
This commit is contained in:
1 parent
9a5c7473f9
commit
2d1c6b1ab8
297 files changed
+3619
-3045
No files matched your search
+2
-3
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -15,4 +14,4 @@ namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProvide
|
||||
public record ReorderLibraryMetadataProvidersCommand(
|
||||
Guid LibraryId,
|
||||
IReadOnlyList<Guid> PluginIds
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
) : ICommand;
|
||||
+16
-8
@@ -1,9 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -16,38 +17,45 @@ namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProvide
|
||||
/// <summary>
|
||||
/// Handler for the command to reorder the metadata providers of a media library.
|
||||
/// </summary>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandler : IRequestHandler<ReorderLibraryMetadataProvidersCommand, ErrorOr<Success>>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<ReorderLibraryMetadataProvidersCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<ReorderLibraryMetadataProvidersCommand> _validator;
|
||||
|
||||
/// <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)
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public ReorderLibraryMetadataProvidersCommandHandler(IUnitOfWork unitOfWork, IValidator<ReorderLibraryMetadataProvidersCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <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="command">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)
|
||||
public async Task<ErrorOr<Success>> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(request.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.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++)
|
||||
for (int rank = 0; rank < command.PluginIds.Count; rank++)
|
||||
{
|
||||
Guid pluginId = request.PluginIds[rank];
|
||||
Guid pluginId = command.PluginIds[rank];
|
||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? configuration))
|
||||
{
|
||||
configuration.Rank = rank + 1;
|
||||
|
||||
+11
-6
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
@@ -15,10 +16,14 @@ public class ReorderLibraryMetadataProvidersCommandValidator : AbstractValidator
|
||||
/// </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);
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginIds)
|
||||
.NotNull()
|
||||
.WithError(Errors.Plugins.PluginIdsListCannotBeNull)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdsListCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
@@ -16,4 +15,4 @@ public record SetLibraryMetadataProviderEnabledCommand(
|
||||
Guid LibraryId,
|
||||
Guid PluginId,
|
||||
bool IsEnabled
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
) : ICommand;
|
||||
+19
-11
@@ -1,9 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -16,31 +17,38 @@ namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEna
|
||||
/// <summary>
|
||||
/// Handler for the command to enable or disable a metadata provider for a media library.
|
||||
/// </summary>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandler : IRequestHandler<SetLibraryMetadataProviderEnabledCommand, ErrorOr<Success>>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<SetLibraryMetadataProviderEnabledCommand> _validator;
|
||||
|
||||
/// <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)
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public SetLibraryMetadataProviderEnabledCommandHandler(IUnitOfWork unitOfWork, IValidator<SetLibraryMetadataProviderEnabledCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <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="command">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)
|
||||
public async Task<ErrorOr<Success>> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await configurationRepository.GetByLibraryAndPluginIdAsync(request.LibraryId, request.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await configurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsError)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
@@ -48,21 +56,21 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : IRequestHandler<S
|
||||
if (getConfigurationResult.Value is not null)
|
||||
{
|
||||
configuration = getConfigurationResult.Value;
|
||||
configuration.IsEnabled = request.IsEnabled;
|
||||
configuration.IsEnabled = command.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);
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.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,
|
||||
LibraryId = command.LibraryId,
|
||||
PluginId = command.PluginId,
|
||||
IsEnabled = command.IsEnabled,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
|
||||
+9
-5
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
@@ -15,9 +16,12 @@ public class SetLibraryMetadataProviderEnabledCommandValidator : AbstractValidat
|
||||
/// </summary>
|
||||
public SetLibraryMetadataProviderEnabledCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.LibraryId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.LibraryIdCannotBeEmpty.Description);
|
||||
RuleFor(x => x.PluginId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.PluginIdCannotBeEmpty.Description);
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -15,4 +14,4 @@ namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
public record UpdatePluginSettingsCommand(
|
||||
Guid PluginId,
|
||||
IReadOnlyDictionary<string, string>? Settings
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
) : ICommand;
|
||||
+16
-7
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,32 +15,39 @@ 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>>
|
||||
public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSettingsCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<UpdatePluginSettingsCommand> _validator;
|
||||
|
||||
/// <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)
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public UpdatePluginSettingsCommandHandler(IUnitOfWork unitOfWork, IValidator<UpdatePluginSettingsCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to update the settings of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="command">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)
|
||||
public async Task<ErrorOr<Success>> HandleAsync(UpdatePluginSettingsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
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);
|
||||
string? settingsJson = command.Settings is not null ? JsonSerializer.Serialize(command.Settings) : null;
|
||||
ErrorOr<Updated> updateResult = await pluginRepository.UpdateSettingsAsync(command.PluginId, settingsJson, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsError)
|
||||
return updateResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
+5
-3
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
@@ -15,7 +16,8 @@ public class UpdatePluginSettingsCommandValidator : AbstractValidator<UpdatePlug
|
||||
/// </summary>
|
||||
public UpdatePluginSettingsCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.PluginId)
|
||||
.NotEmpty().WithMessage(Errors.Plugins.PluginIdCannotBeEmpty.Description);
|
||||
RuleFor(command => command.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -1,9 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
@@ -14,4 +11,4 @@ namespace Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
/// <param name="LibraryId">The Id of the media library whose metadata providers are retrieved.</param>
|
||||
public record GetLibraryMetadataProvidersQuery(
|
||||
Guid LibraryId
|
||||
) : IRequest<ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>>;
|
||||
) : IQuery;
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
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;
|
||||
@@ -18,7 +18,7 @@ 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>>>
|
||||
public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryMetadataProvidersQuery, ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -34,15 +34,15 @@ public class GetLibraryMetadataProvidersQueryHandler : IRequestHandler<GetLibrar
|
||||
/// <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="query">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)
|
||||
public async Task<ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(request.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
|
||||
+2
-4
@@ -1,7 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
@@ -13,4 +11,4 @@ namespace Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
/// <param name="PluginId">The unique identifier of the plugin.</param>
|
||||
public record GetPluginSettingsQuery(
|
||||
Guid PluginId
|
||||
) : IRequest<ErrorOr<PluginSettingsResponse>>;
|
||||
) : IQuery;
|
||||
+7
-7
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -8,7 +9,6 @@ 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;
|
||||
@@ -20,7 +20,7 @@ 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>>
|
||||
public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuery, ErrorOr<PluginSettingsResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
@@ -39,15 +39,15 @@ public class GetPluginSettingsQueryHandler : IRequestHandler<GetPluginSettingsQu
|
||||
/// <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="query">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)
|
||||
public async Task<ErrorOr<PluginSettingsResponse>> HandleAsync(GetPluginSettingsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(request.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsError)
|
||||
return getPluginResult.Errors;
|
||||
PluginEntity? pluginEntity = getPluginResult.Value;
|
||||
@@ -55,10 +55,10 @@ public class GetPluginSettingsQueryHandler : IRequestHandler<GetPluginSettingsQu
|
||||
return Errors.Plugins.PluginNotFound;
|
||||
|
||||
// the schema comes from the loaded plugin, the current values from the storage medium
|
||||
IPlugin? loadedPlugin = _pluginManager.GetPlugin(request.PluginId);
|
||||
IPlugin? loadedPlugin = _pluginManager.GetPlugin(query.PluginId);
|
||||
IReadOnlyList<PluginSettingDescriptorResponse> schema = loadedPlugin is not null
|
||||
? loadedPlugin.GetSettingsSchema().Select(setting => setting.ToResponse()).ToList()
|
||||
: [];
|
||||
return new PluginSettingsResponse(request.PluginId, schema, pluginEntity.ToSettings());
|
||||
return new PluginSettingsResponse(query.PluginId, schema, pluginEntity.ToSettings());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
@@ -10,4 +7,4 @@ namespace Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
/// <summary>
|
||||
/// Query for getting all the detected plugins.
|
||||
/// </summary>
|
||||
public record GetPluginsQuery() : IRequest<ErrorOr<IReadOnlyList<PluginResponse>>>;
|
||||
public record GetPluginsQuery() : IQuery;
|
||||
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
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;
|
||||
@@ -17,7 +17,7 @@ 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>>>
|
||||
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, ErrorOr<IReadOnlyList<PluginResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -33,12 +33,12 @@ public class GetPluginsQueryHandler : IRequestHandler<GetPluginsQuery, ErrorOr<I
|
||||
/// <summary>
|
||||
/// Handles the query to get all the detected plugins.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="query">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)
|
||||
public async Task<ErrorOr<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Reference in new issue
Block a user