mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Replaces ErrorOr library with a custom implementation.
This commit is contained in:
1 parent
8fe90a4dde
commit
3b772d68ca
436 files changed
+4234
-3922
No files matched your search
+8
-8
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -17,7 +17,7 @@ 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 : ICommandHandler<ReorderLibraryMetadataProvidersCommand, ErrorOr<Success>>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<ReorderLibraryMetadataProvidersCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<ReorderLibraryMetadataProvidersCommand> _validator;
|
||||
@@ -39,17 +39,17 @@ public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<Reo
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<Success>> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<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(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
Dictionary<Guid, LibraryMetadataProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
||||
@@ -59,8 +59,8 @@ public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<Reo
|
||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? configuration))
|
||||
{
|
||||
configuration.Rank = rank + 1;
|
||||
ErrorOr<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsError)
|
||||
Result<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -17,7 +17,7 @@ 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 : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, ErrorOr<Success>>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<SetLibraryMetadataProviderEnabledCommand> _validator;
|
||||
@@ -39,17 +39,17 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<S
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<Success>> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<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(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsError)
|
||||
Result<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await configurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsFailure)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
LibraryMetadataProviderConfigurationEntity configuration;
|
||||
@@ -61,8 +61,8 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<S
|
||||
else
|
||||
{
|
||||
// compute the rank to assign to the new configuration, appending it after the existing ones
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
int nextRank = getConfigurationsResult.Value.Count == 0 ? 1 : getConfigurationsResult.Value.Max(configuration => configuration.Rank) + 1;
|
||||
configuration = new LibraryMetadataProviderConfigurationEntity
|
||||
@@ -78,8 +78,8 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<S
|
||||
};
|
||||
}
|
||||
|
||||
ErrorOr<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsError)
|
||||
Result<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -15,7 +15,7 @@ namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
/// <summary>
|
||||
/// Handler for the command to update the settings of a plugin.
|
||||
/// </summary>
|
||||
public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSettingsCommand, ErrorOr<Success>>
|
||||
public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSettingsCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<UpdatePluginSettingsCommand> _validator;
|
||||
@@ -37,9 +37,9 @@ public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSe
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<Success>> HandleAsync(UpdatePluginSettingsCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<Success>> HandleAsync(UpdatePluginSettingsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -47,8 +47,8 @@ public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSe
|
||||
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
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)
|
||||
Result<Updated> updateResult = await pluginRepository.UpdateSettingsAsync(command.PluginId, settingsJson, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -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 : IQueryHandler<GetLibraryMetadataProvidersQuery, ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryMetadataProvidersQuery, Result<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -37,19 +37,19 @@ public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryM
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
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)
|
||||
Result<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsFailure)
|
||||
return getPluginsResult.Errors;
|
||||
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -7,7 +7,7 @@ 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.Domain.Common.Errors;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -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 : IQueryHandler<GetPluginSettingsQuery, ErrorOr<PluginSettingsResponse>>
|
||||
public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuery, Result<PluginSettingsResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
@@ -42,13 +42,13 @@ public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuer
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="PluginSettingsResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<PluginSettingsResponse>> HandleAsync(GetPluginSettingsQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<PluginSettingsResponse>> HandleAsync(GetPluginSettingsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsError)
|
||||
Result<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsFailure)
|
||||
return getPluginResult.Errors;
|
||||
PluginEntity? pluginEntity = getPluginResult.Value;
|
||||
if (pluginEntity is null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -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 : IQueryHandler<GetPluginsQuery, ErrorOr<IReadOnlyList<PluginResponse>>>
|
||||
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IReadOnlyList<PluginResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -36,14 +36,14 @@ public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, ErrorOr<IRe
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="PluginResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getPluginsResult.Match(
|
||||
plugins => ErrorOrFactory.From<IReadOnlyList<PluginResponse>>(plugins.Select(plugin => plugin.ToResponse()).ToList()),
|
||||
plugins => Result.From<IReadOnlyList<PluginResponse>>(plugins.Select(plugin => plugin.ToResponse()).ToList()),
|
||||
errors => errors);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user