mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Adds provider configuration to media library saves
Moves metadata provider, artwork provider, and book reader choices into the add and update library requests, adds the library type lookups, removes the per-provider enable and reorder endpoints, and reconciles the stored configurations in one provider store call. Tightens library update and delete authorization to require ownership and the manage permission, and cleans up enum validation, comments, resource diacritics, and Razor imports.
This commit is contained in:
1 parent
2e7563199a
commit
48ad8692af
148 files changed
+6305
-2936
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the choice made for one metadata provider, artwork provider or book reader of a media library, carried by the commands that create or update a media library.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The Id of the plugin providing the metadata provider, artwork provider or book reader.</param>
|
||||
/// <param name="IsEnabled">Whether the provider or reader is enabled for the media library. When absent, the stored state is kept, and a provider or reader without a stored state starts disabled.</param>
|
||||
[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
|
||||
public record LibraryProviderSelectionDto(
|
||||
Guid PluginId,
|
||||
bool? IsEnabled
|
||||
);
|
||||
+43
-33
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
@@ -11,7 +12,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Application.Common.Infrastructure.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Store of the metadata and artwork provider configurations of the media libraries.
|
||||
/// Store of the metadata provider, artwork provider and book reader configurations of the media libraries.
|
||||
/// </summary>
|
||||
public interface IMediaLibraryProviderConfigurationStore
|
||||
{
|
||||
@@ -24,25 +25,18 @@ public interface IMediaLibraryProviderConfigurationStore
|
||||
Task<Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetConfigurationsAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a disabled provider configuration for every loaded plugin that supports the provided library type and has no
|
||||
/// Adds a disabled metadata provider, artwork provider and book reader configuration for every loaded plugin that supports the provided library type and has no
|
||||
/// configuration yet for the media library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The added configurations are only staged until the unit of work is saved, and are not visible to a later ensure, so it must be called at most once per media library before the changes are saved.
|
||||
/// </remarks>
|
||||
/// <param name="libraryId">The Id of the media library whose provider configurations are ensured.</param>
|
||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> EnsureProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the provider configurations of the media library identified by <paramref name="libraryId"/> so that they
|
||||
/// match the plugins supporting the provided library type.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose provider configurations are reconciled.</param>
|
||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> ReconcileProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all the provider configurations of the media library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
@@ -60,36 +54,52 @@ public interface IMediaLibraryProviderConfigurationStore
|
||||
Task<Result<Deleted>> RemoveProviderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a disabled book reader configuration for every loaded plugin that supports the provided library type and has no configuration yet, for the media library identified by <paramref name="libraryId"/>.
|
||||
/// Makes the provider and book reader configurations of the media library identified by <paramref name="libraryId"/> match the plugins supporting the provided library type, and applies the choices made for them.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are ensured.</param>
|
||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
||||
/// <remarks>
|
||||
/// A list that is provided reconciles that kind of configuration with the library type and applies the choices: the configurations of the plugins that do not support the library type
|
||||
/// are removed, even when the list does not name them, every supported plugin gets a configuration, and the list sets the enabled state of every provider or reader it names and, for the
|
||||
/// metadata and artwork providers, their order. A choice without an enabled state keeps the stored state, the supported plugins the list does not name keep their stored state and are
|
||||
/// ordered after the named ones, and a plugin without a stored configuration starts disabled. A list that is <see langword="null"/> leaves that kind of configuration untouched, unless
|
||||
/// <paramref name="shouldReconcileOmittedKinds"/> is <see langword="true"/>, in which case it is reconciled the same way, without choices. Whenever the book reader configurations are
|
||||
/// reconciled or chosen, the cached reader enablements of the library are dropped.
|
||||
/// </remarks>
|
||||
/// <param name="libraryId">The Id of the media library whose provider and book reader configurations are configured.</param>
|
||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers and book readers apply.</param>
|
||||
/// <param name="metadataProviders">The choices made for the metadata providers, in the order in which they are tried.</param>
|
||||
/// <param name="artworkProviders">The choices made for the artwork providers, in the order in which they are tried.</param>
|
||||
/// <param name="bookReaders">The choices made for the book readers.</param>
|
||||
/// <param name="shouldReconcileOmittedKinds">Whether the kinds of configuration whose list of choices is <see langword="null"/> are reconciled with the library type, which is needed when the
|
||||
/// library is new or its type changed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error when a choice names a plugin that does not support the library type.</returns>
|
||||
Task<Result<Success>> ConfigureProvidersAsync(
|
||||
Guid libraryId,
|
||||
LibraryType libraryType,
|
||||
IReadOnlyList<LibraryProviderSelectionDto>? metadataProviders,
|
||||
IReadOnlyList<LibraryProviderSelectionDto>? artworkProviders,
|
||||
IReadOnlyList<LibraryProviderSelectionDto>? bookReaders,
|
||||
bool shouldReconcileOmittedKinds,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the book reader configurations of the media library identified by <paramref name="libraryId"/> so that they match the plugins supporting the provided library type.
|
||||
/// Gets the Ids of the loaded plugins that provide metadata for the provided library type, ordered alphabetically by plugin name.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are reconciled.</param>
|
||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
||||
/// <param name="libraryType">The type of the media library the metadata providers must support.</param>
|
||||
/// <returns>The Ids of the plugins providing metadata for the library type.</returns>
|
||||
IReadOnlyList<Guid> GetSupportedMetadataProviderPluginIds(LibraryType libraryType);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all the book reader configurations of the media library identified by <paramref name="libraryId"/>.
|
||||
/// Gets the Ids of the loaded plugins that provide artwork for the provided library type, ordered alphabetically by plugin name.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> RemoveBookReaderConfigurationsForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
/// <param name="libraryType">The type of the media library the artwork providers must support.</param>
|
||||
/// <returns>The Ids of the plugins providing artwork for the library type.</returns>
|
||||
IReadOnlyList<Guid> GetSupportedArtworkProviderPluginIds(LibraryType libraryType);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all the book reader configurations referencing the plugin identified by <paramref name="pluginId"/>.
|
||||
/// Gets the Ids of the loaded plugins that provide a book reader for the provided library type, ordered alphabetically by plugin name.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">The Id of the plugin whose book reader configurations are deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> RemoveBookReaderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
|
||||
/// <param name="libraryType">The type of the media library the book readers must support.</param>
|
||||
/// <returns>The Ids of the plugins providing a book reader for the library type.</returns>
|
||||
IReadOnlyList<Guid> GetSupportedBookReaderPluginIds(LibraryType libraryType);
|
||||
}
|
||||
+9
-1
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
@@ -15,6 +16,10 @@ public static class AddMediaLibraryRequestMapping
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A path template part that is <see langword="null"/> is converted to a part without a kind, and a provider or book reader choice that is <see langword="null"/> is
|
||||
/// converted to a choice without a plugin Id, so that the validation of the command reports them, instead of the conversion failing before the command is validated.
|
||||
/// </remarks>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
|
||||
@@ -32,7 +37,10 @@ public static class AddMediaLibraryRequestMapping
|
||||
request.IsContentOnSsd,
|
||||
request.ShouldTrackConsumptionProgress,
|
||||
request.CompletionThresholdPercentage,
|
||||
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
|
||||
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part?.Kind, part?.Representation, part?.IsOptional ?? false)).ToArray(),
|
||||
request.MetadataProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||
request.ArtworkProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||
request.BookReaders?.Select(reader => new LibraryProviderSelectionDto(reader?.PluginId ?? Guid.Empty, reader?.IsEnabled)).ToArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
@@ -15,13 +16,16 @@ public static class UpdateLibraryRequestMapping
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="UpdateLibraryCommand"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A path template part that is <see langword="null"/> is converted to a part without a kind, and a provider or book reader choice that is <see langword="null"/> is
|
||||
/// converted to a choice without a plugin Id, so that the validation of the command reports them, instead of the conversion failing before the command is validated.
|
||||
/// </remarks>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static UpdateLibraryCommand ToCommand(this UpdateLibraryRequest request)
|
||||
{
|
||||
return new UpdateLibraryCommand(
|
||||
request.Id,
|
||||
request.UserId,
|
||||
request.Title,
|
||||
request.LibraryType,
|
||||
request.ContentLocations,
|
||||
@@ -34,7 +38,10 @@ public static class UpdateLibraryRequestMapping
|
||||
request.IsContentOnSsd,
|
||||
request.ShouldTrackConsumptionProgress,
|
||||
request.CompletionThresholdPercentage,
|
||||
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
|
||||
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part?.Kind, part?.Representation, part?.IsOptional ?? false)).ToArray(),
|
||||
request.MetadataProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||
request.ArtworkProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||
request.BookReaders?.Select(reader => new LibraryProviderSelectionDto(reader?.PluginId ?? Guid.Empty, reader?.IsEnabled)).ToArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetLibraryTypeArtworkProvidersRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetLibraryTypeArtworkProvidersRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeArtworkProvidersQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetLibraryTypeArtworkProvidersQuery ToQuery(this GetLibraryTypeArtworkProvidersRequest request)
|
||||
{
|
||||
return new GetLibraryTypeArtworkProvidersQuery(
|
||||
request.LibraryType
|
||||
);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetLibraryTypeBookReadersRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetLibraryTypeBookReadersRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeBookReadersQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetLibraryTypeBookReadersQuery ToQuery(this GetLibraryTypeBookReadersRequest request)
|
||||
{
|
||||
return new GetLibraryTypeBookReadersQuery(
|
||||
request.LibraryType
|
||||
);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetLibraryTypeMetadataProvidersRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetLibraryTypeMetadataProvidersRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeMetadataProvidersQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetLibraryTypeMetadataProvidersQuery ToQuery(this GetLibraryTypeMetadataProvidersRequest request)
|
||||
{
|
||||
return new GetLibraryTypeMetadataProvidersQuery(
|
||||
request.LibraryType
|
||||
);
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ReorderLibraryArtworkProvidersRequest"/>.
|
||||
/// </summary>
|
||||
public static class ReorderLibraryArtworkProvidersRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="ReorderLibraryArtworkProvidersCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static ReorderLibraryArtworkProvidersCommand ToCommand(this ReorderLibraryArtworkProvidersRequest request)
|
||||
{
|
||||
return new ReorderLibraryArtworkProvidersCommand(
|
||||
LibraryId: request.LibraryId,
|
||||
PluginIds: request.PluginIds
|
||||
);
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="SetLibraryArtworkProviderEnabledRequest"/>.
|
||||
/// </summary>
|
||||
public static class SetLibraryArtworkProviderEnabledRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="SetLibraryArtworkProviderEnabledCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static SetLibraryArtworkProviderEnabledCommand ToCommand(this SetLibraryArtworkProviderEnabledRequest request)
|
||||
{
|
||||
return new SetLibraryArtworkProviderEnabledCommand(
|
||||
LibraryId: request.LibraryId,
|
||||
PluginId: request.PluginId,
|
||||
IsEnabled: request.IsEnabled
|
||||
);
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="SetLibraryBookReaderEnabledRequest"/>.
|
||||
/// </summary>
|
||||
public static class SetLibraryBookReaderEnabledRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="SetLibraryBookReaderEnabledCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static SetLibraryBookReaderEnabledCommand ToCommand(this SetLibraryBookReaderEnabledRequest request)
|
||||
{
|
||||
return new SetLibraryBookReaderEnabledCommand(
|
||||
request.LibraryId,
|
||||
request.PluginId,
|
||||
request.IsEnabled
|
||||
);
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Favorites.Commands.RemoveFavorite;
|
||||
@@ -26,9 +25,12 @@ public class RemoveFavoriteCommandValidator : AbstractValidator<RemoveFavoriteCo
|
||||
// Only the member names other than the default None are accepted, so a numeric route value that happens to parse as an
|
||||
// enumeration value, or the explicit default value, is rejected.
|
||||
RuleFor(command => command.MediaKind)
|
||||
.Must(mediaKind => Enum.GetNames<FavoriteMediaKind>()
|
||||
.Where(mediaKindName => !string.Equals(mediaKindName, nameof(FavoriteMediaKind.None), StringComparison.Ordinal))
|
||||
.Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
|
||||
.IsInEnum<RemoveFavoriteCommand, FavoriteMediaKind>()
|
||||
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
||||
.WithError(Errors.Favorites.FavoriteMediaKindIsInvalid);
|
||||
|
||||
RuleFor(command => command.MediaKind)
|
||||
.Must(mediaKind => !string.Equals(mediaKind, nameof(FavoriteMediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
||||
.WithError(Errors.Favorites.FavoriteMediaKindIsInvalid);
|
||||
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Commands.StartConsumption;
|
||||
@@ -35,7 +34,7 @@ public class StartConsumptionCommandValidator : AbstractValidator<StartConsumpti
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
RuleFor(command => command.MediaKind)
|
||||
.Must(mediaKind => Enum.GetNames<MediaKind>().Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
|
||||
.IsInEnum<StartConsumptionCommand, MediaKind>()
|
||||
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetResumePoint;
|
||||
@@ -25,7 +24,7 @@ public class GetResumePointQueryValidator : AbstractValidator<GetResumePointQuer
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => Enum.GetNames<MediaKind>().Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
|
||||
.IsInEnum<GetResumePointQuery, MediaKind>()
|
||||
.When(query => query.MediaKind is not null && query.MediaKind.Length > 0)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
|
||||
+7
-1
@@ -22,6 +22,9 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. When absent, the default of the library type is used.</param>
|
||||
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. When absent, the default of the library type is used on creation.</param>
|
||||
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk.</param>
|
||||
/// <param name="MetadataProviders">The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, every provider supported by the library type is added disabled.</param>
|
||||
/// <param name="ArtworkProviders">The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, every provider supported by the library type is added disabled.</param>
|
||||
/// <param name="BookReaders">The book readers of the media library, and whether each one is enabled. When absent, every reader supported by the library type is added disabled.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public record AddLibraryCommand(
|
||||
string? Title,
|
||||
@@ -36,5 +39,8 @@ public record AddLibraryCommand(
|
||||
bool IsContentOnSsd,
|
||||
bool? ShouldTrackConsumptionProgress,
|
||||
int? CompletionThresholdPercentage,
|
||||
LibraryPathTemplatePartDto[]? PathTemplateParts
|
||||
LibraryPathTemplatePartDto[]? PathTemplateParts,
|
||||
LibraryProviderSelectionDto[]? MetadataProviders,
|
||||
LibraryProviderSelectionDto[]? ArtworkProviders,
|
||||
LibraryProviderSelectionDto[]? BookReaders
|
||||
) : ICommand;
|
||||
+7
-7
@@ -114,7 +114,7 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
|
||||
return DomainErrors.Library.CoverFileMustBeAnImage;
|
||||
}
|
||||
|
||||
LibraryType libraryType = Enum.Parse<LibraryType>(command.LibraryType!);
|
||||
LibraryType libraryType = Enum.Parse<LibraryType>(command.LibraryType!, ignoreCase: true);
|
||||
|
||||
// A library created without explicit consumption settings uses the defaults of its type. When progress tracking is on and no threshold is
|
||||
// supplied, the default threshold of the type is used; a type without one keeps no threshold, which means completion is recorded explicitly.
|
||||
@@ -158,15 +158,15 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
|
||||
|
||||
// Convert the domain library entity to a repository library entity.
|
||||
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
|
||||
// Insert the repository entity, seed the provider configurations of the new library so that it lists the plugins
|
||||
// providing metadata or artwork for its type, and save the changes.
|
||||
// Insert the repository entity, seed the provider configurations of the new library so that it lists the plugins providing metadata,
|
||||
// artwork or book readers for its type, with the choices made for them, and save the changes.
|
||||
Result<Created> insertLibraryResult = await _unitOfWork.LibraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
|
||||
if (insertLibraryResult.IsFailure)
|
||||
return insertLibraryResult.Errors;
|
||||
Result<Success> ensureProviderConfigurationsResult = await _providerConfigurationStore.EnsureProviderConfigurationsAsync(
|
||||
createLibraryResult.Value.Id.Value, libraryType, cancellationToken).ConfigureAwait(false);
|
||||
if (ensureProviderConfigurationsResult.IsFailure)
|
||||
return ensureProviderConfigurationsResult.Errors;
|
||||
Result<Success> configureProvidersResult = await _providerConfigurationStore.ConfigureProvidersAsync(
|
||||
createLibraryResult.Value.Id.Value, libraryType, command.MetadataProviders, command.ArtworkProviders, command.BookReaders, shouldReconcileOmittedKinds: true, cancellationToken).ConfigureAwait(false);
|
||||
if (configureProvidersResult.IsFailure)
|
||||
return configureProvidersResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
|
||||
+29
-1
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
@@ -21,7 +22,7 @@ public class AddLibraryCommandValidator : AbstractValidator<AddLibraryCommand>
|
||||
RuleFor(command => command.LibraryType)
|
||||
.NotNull()
|
||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||
.Must(libraryType => Enum.TryParse<LibraryType>(libraryType, out _))
|
||||
.IsInEnum<AddLibraryCommand, LibraryType>()
|
||||
.WithError(Errors.Library.UnknownLibraryType);
|
||||
|
||||
RuleFor(command => command.ContentLocations)
|
||||
@@ -61,5 +62,32 @@ public class AddLibraryCommandValidator : AbstractValidator<AddLibraryCommand>
|
||||
.When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty);
|
||||
});
|
||||
|
||||
RuleForEach(command => command.MetadataProviders)
|
||||
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||
|
||||
RuleFor(command => command.MetadataProviders)
|
||||
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||
|
||||
RuleForEach(command => command.ArtworkProviders)
|
||||
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||
|
||||
RuleFor(command => command.ArtworkProviders)
|
||||
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||
|
||||
RuleForEach(command => command.BookReaders)
|
||||
.ChildRules(reader => reader.RuleFor(selection => selection.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||
|
||||
RuleFor(command => command.BookReaders)
|
||||
.Must(readers => readers is null || readers.Select(selection => selection.PluginId).Distinct().Count() == readers.Length)
|
||||
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -13,6 +13,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -85,10 +86,12 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
|
||||
else if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// Admins can delete any library; for everyone else, only the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
// Admins can delete any library. Everyone else can only delete the libraries they own, and only while they hold the permission to manage media
|
||||
// libraries, which can be withheld to keep a user from deleting even the libraries they own.
|
||||
if (!await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false))
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
if (!await _authorizationService.IsInRoleAsync(userId, AuthorizationRoles.ADMIN, cancellationToken).ConfigureAwait(false) &&
|
||||
!await _authorizationService.HasPermissionAsync(userId, AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false))
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// Create a domain library object.
|
||||
|
||||
+7
-3
@@ -11,7 +11,6 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
|
||||
/// Command for updating a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the media library.</param>
|
||||
/// <param name="OwnerId">The unique identifier of the user owning the media library.</param>
|
||||
/// <param name="Title">The title of the media library.</param>
|
||||
/// <param name="LibraryType">The type of the media library.</param>
|
||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located.</param>
|
||||
@@ -25,10 +24,12 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
|
||||
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. When absent, the stored value is kept.</param>
|
||||
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. When absent, the stored value is kept.</param>
|
||||
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk.</param>
|
||||
/// <param name="MetadataProviders">The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||
/// <param name="ArtworkProviders">The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||
/// <param name="BookReaders">The book readers of the media library, and whether each one is enabled. When absent, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public record UpdateLibraryCommand(
|
||||
Guid Id,
|
||||
Guid OwnerId,
|
||||
string? Title,
|
||||
string? LibraryType,
|
||||
string[]? ContentLocations,
|
||||
@@ -41,5 +42,8 @@ public record UpdateLibraryCommand(
|
||||
bool IsContentOnSsd,
|
||||
bool? ShouldTrackConsumptionProgress,
|
||||
int? CompletionThresholdPercentage,
|
||||
LibraryPathTemplatePartDto[]? PathTemplateParts
|
||||
LibraryPathTemplatePartDto[]? PathTemplateParts,
|
||||
LibraryProviderSelectionDto[]? MetadataProviders,
|
||||
LibraryProviderSelectionDto[]? ArtworkProviders,
|
||||
LibraryProviderSelectionDto[]? BookReaders
|
||||
) : ICommand;
|
||||
+22
-15
@@ -105,6 +105,16 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
||||
else if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// Admins can update any library. Everyone else can only update the libraries they own, and only while they hold the permission to manage media
|
||||
// libraries, which can be withheld to keep a user from changing even the libraries they own. Authorization comes before the cover image is
|
||||
// read, so a user who may not update the library can never make the server open a path on their behalf.
|
||||
if (!await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false))
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
if (!await _authorizationService.IsInRoleAsync(userId, AuthorizationRoles.ADMIN, cancellationToken).ConfigureAwait(false) &&
|
||||
!await _authorizationService.HasPermissionAsync(userId, AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false))
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
bool hasProviderChoices = command.MetadataProviders is not null || command.ArtworkProviders is not null || command.BookReaders is not null;
|
||||
|
||||
// Make sure the file is an actual supported image, but only when a new cover image was chosen; the stored cover image is
|
||||
// relative to the application base directory and is already validated, so it must not block saving unrelated changes.
|
||||
if (command.CoverImage is not null && command.CoverImage != getLibraryResult.Value.CoverImage)
|
||||
@@ -120,15 +130,8 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
||||
return DomainErrors.Library.CoverFileMustBeAnImage;
|
||||
}
|
||||
|
||||
// Admins or users with the permission to manage media libraries can update any library; other users can only update the libraries they own.
|
||||
bool hasManagePermission = await _authorizationService.HasPermissionAsync(userId, AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false);
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false);
|
||||
if (!hasManagePermission && !canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// Create a domain library object.
|
||||
LibraryType newLibraryType = Enum.Parse<LibraryType>(command.LibraryType!);
|
||||
LibraryType newLibraryType = Enum.Parse<LibraryType>(command.LibraryType!, ignoreCase: true);
|
||||
|
||||
// Keep the stored consumption settings unless the request explicitly changes them. When progress tracking is enabled and
|
||||
// no threshold is supplied, the stored threshold is kept; the value object never retains a threshold while tracking is disabled.
|
||||
@@ -157,9 +160,10 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
||||
if (pathTemplateResult.IsFailure)
|
||||
return pathTemplateResult.Errors;
|
||||
|
||||
// The owner of a library is the user who created it, and an update never changes it.
|
||||
Result<Library> createLibraryResult = Library.Create(
|
||||
LibraryId.Create(command.Id),
|
||||
UserId.Create(command.OwnerId),
|
||||
UserId.Create(getLibraryResult.Value.UserId),
|
||||
command.Title!,
|
||||
newLibraryType,
|
||||
command.ContentLocations!,
|
||||
@@ -179,16 +183,19 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
||||
// Convert the domain library entity to a repository library entity.
|
||||
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
|
||||
|
||||
// Update the repository entity, and when the library type changed, reconcile the provider configurations so that
|
||||
// they match the plugins supporting the new type, and save the changes.
|
||||
// Update the repository entity, apply the choices made for the providers, and when the library type changed, also reconcile the kinds of
|
||||
// configuration that were not chosen, so they match the plugins supporting the new type; then save the changes. When the type is unchanged,
|
||||
// a kind of configuration that was not chosen is left untouched.
|
||||
Result<Updated> updateLibraryResult = await _unitOfWork.LibraryRepository.UpdateAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
|
||||
if (updateLibraryResult.IsFailure)
|
||||
return updateLibraryResult.Errors;
|
||||
if (getLibraryResult.Value.LibraryType != newLibraryType)
|
||||
bool isLibraryTypeChanged = getLibraryResult.Value.LibraryType != newLibraryType;
|
||||
if (isLibraryTypeChanged || hasProviderChoices)
|
||||
{
|
||||
Result<Success> reconcileResult = await _providerConfigurationStore.ReconcileProviderConfigurationsAsync(command.Id, newLibraryType, cancellationToken).ConfigureAwait(false);
|
||||
if (reconcileResult.IsFailure)
|
||||
return reconcileResult.Errors;
|
||||
Result<Success> configureProvidersResult = await _providerConfigurationStore.ConfigureProvidersAsync(
|
||||
command.Id, newLibraryType, command.MetadataProviders, command.ArtworkProviders, command.BookReaders, isLibraryTypeChanged, cancellationToken).ConfigureAwait(false);
|
||||
if (configureProvidersResult.IsFailure)
|
||||
return configureProvidersResult.Errors;
|
||||
}
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
|
||||
+29
-7
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
||||
@@ -24,16 +25,10 @@ public class UpdateLibraryCommandValidator : AbstractValidator<UpdateLibraryComm
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.OwnerId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Users.UserIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Users.UserIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.LibraryType)
|
||||
.NotNull()
|
||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||
.Must(libraryType => Enum.TryParse<LibraryType>(libraryType, out _))
|
||||
.IsInEnum<UpdateLibraryCommand, LibraryType>()
|
||||
.WithError(Errors.Library.UnknownLibraryType);
|
||||
|
||||
RuleFor(command => command.ContentLocations)
|
||||
@@ -73,5 +68,32 @@ public class UpdateLibraryCommandValidator : AbstractValidator<UpdateLibraryComm
|
||||
.When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty);
|
||||
});
|
||||
|
||||
RuleForEach(command => command.MetadataProviders)
|
||||
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||
|
||||
RuleFor(command => command.MetadataProviders)
|
||||
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||
|
||||
RuleForEach(command => command.ArtworkProviders)
|
||||
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||
|
||||
RuleFor(command => command.ArtworkProviders)
|
||||
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||
|
||||
RuleForEach(command => command.BookReaders)
|
||||
.ChildRules(reader => reader.RuleFor(selection => selection.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||
|
||||
RuleFor(command => command.BookReaders)
|
||||
.Must(readers => readers is null || readers.Select(selection => selection.PluginId).Distinct().Count() == readers.Length)
|
||||
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -41,19 +41,19 @@ public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler<GetLibraryP
|
||||
/// </returns>
|
||||
public Task<Result<LibraryPathTemplateCatalogResponse>> HandleAsync(GetLibraryPathTemplatePartsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// the library type travels as a string taken from the route, and is matched against the enum the same way the create and update
|
||||
// The library type travels as a string taken from the route, and is matched against the enum the same way the create and update
|
||||
// library commands do, so that a malformed type is reported as an unknown library type instead of silently returning an empty catalog.
|
||||
if (!Enum.TryParse(query.LibraryType, ignoreCase: true, out LibraryType libraryType))
|
||||
if (!Enum.TryParse(query.LibraryType, ignoreCase: true, out LibraryType libraryType) || !Enum.IsDefined(libraryType))
|
||||
return Task.FromResult<Result<LibraryPathTemplateCatalogResponse>>(DomainErrors.Library.UnknownLibraryType);
|
||||
|
||||
// only the catalog registered for the requested library type applies, so the parts and the default structure offered to the user are
|
||||
// Only the catalog registered for the requested library type applies, so the parts and the default structure offered to the user are
|
||||
// type aware (music libraries get artist and release parts, book libraries get author and title parts, and so on).
|
||||
ILibraryPathPartCatalog? catalog = _catalogs.FirstOrDefault(candidate => candidate.SupportedLibraryType == libraryType);
|
||||
if (catalog is null)
|
||||
// a library type without a catalog has no structure to describe, so an empty catalog is returned, which the client uses to hide the editor.
|
||||
// A library type without a catalog has no structure to describe, so an empty catalog is returned, which the client uses to hide the editor.
|
||||
return Task.FromResult(Result<LibraryPathTemplateCatalogResponse>.Success(new LibraryPathTemplateCatalogResponse([], [])));
|
||||
|
||||
// the selectable parts describe what the user can drop into the template, together with the value type and the default on-disk representation of each part.
|
||||
// The selectable parts describe what the user can drop into the template, together with the value type and the default on-disk representation of each part.
|
||||
List<LibraryPathPartDefinitionResponse> parts =
|
||||
[
|
||||
.. catalog.GetPartDefinitions().Select(definition => new LibraryPathPartDefinitionResponse(
|
||||
@@ -62,7 +62,7 @@ public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler<GetLibraryP
|
||||
definition.DefaultRepresentation,
|
||||
definition.IsOptionalByDefault))
|
||||
];
|
||||
// the default template parts describe the ideal structure the application expects, pre-filled in the editor so the user only edits what deviates.
|
||||
// The default template parts describe the ideal structure the application expects, pre-filled in the editor so the user only edits what deviates.
|
||||
List<LibraryPathTemplatePartResponse> defaultTemplateParts =
|
||||
[
|
||||
.. catalog.GetDefaultTemplate().Parts.Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional))
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Command for reordering the artwork providers of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose artwork providers are reordered.</param>
|
||||
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank.</param>
|
||||
public record ReorderLibraryArtworkProvidersCommand(
|
||||
Guid LibraryId,
|
||||
IReadOnlyList<Guid> PluginIds
|
||||
) : ICommand;
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
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.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to reorder the artwork providers of a media library.
|
||||
/// </summary>
|
||||
public class ReorderLibraryArtworkProvidersCommandHandler : ICommandHandler<ReorderLibraryArtworkProvidersCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<ReorderLibraryArtworkProvidersCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public ReorderLibraryArtworkProvidersCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<ReorderLibraryArtworkProvidersCommand> validator)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to reorder the artwork providers of a media library.
|
||||
/// </summary>
|
||||
/// <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="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<Success>> HandleAsync(ReorderLibraryArtworkProvidersCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// Admins can reorder the artwork providers of any library; for everyone else, only their own libraries.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// Load the artwork provider configurations that are currently registered for the library, so that only providers it actually has are reordered.
|
||||
Result<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.ArtworkProviderConfigurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
// Index the configurations by plugin id, so that each requested plugin can be matched without repeatedly searching the list.
|
||||
Dictionary<Guid, LibraryArtworkProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
||||
// Walk the requested order and assign each provider the 1-based rank that matches its position in the command, so the persisted order follows the user's choice.
|
||||
for (int rank = 0; rank < command.PluginIds.Count; rank++)
|
||||
{
|
||||
Guid pluginId = command.PluginIds[rank];
|
||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryArtworkProviderConfigurationEntity? configuration))
|
||||
{
|
||||
configuration.Rank = rank + 1;
|
||||
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
// Persist all the rank changes in a single save, so that the reorder is applied atomically.
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="ReorderLibraryArtworkProvidersCommand"/>.
|
||||
/// </summary>
|
||||
public class ReorderLibraryArtworkProvidersCommandValidator : AbstractValidator<ReorderLibraryArtworkProvidersCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public ReorderLibraryArtworkProvidersCommandValidator()
|
||||
{
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginIds)
|
||||
.NotNull()
|
||||
.WithError(Errors.Plugins.PluginIdsListCannotBeNull)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdsListCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
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
|
||||
) : ICommand;
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#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 : ICommandHandler<ReorderLibraryMetadataProvidersCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<ReorderLibraryMetadataProvidersCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public ReorderLibraryMetadataProvidersCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<ReorderLibraryMetadataProvidersCommand> validator)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to reorder the metadata providers of a media library.
|
||||
/// </summary>
|
||||
/// <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="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<Success>> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// Admins can reorder the metadata providers of any library; for everyone else, only their own libraries.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// Load the metadata provider configurations that are currently registered for the library, so that only providers it actually has are reordered.
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
// Index the configurations by plugin id, so that each requested plugin can be matched without repeatedly searching the list.
|
||||
Dictionary<Guid, LibraryMetadataProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
||||
// Walk the requested order and assign each provider the 1-based rank that matches its position in the command, so the persisted order follows the user's choice.
|
||||
for (int rank = 0; rank < command.PluginIds.Count; rank++)
|
||||
{
|
||||
Guid pluginId = command.PluginIds[rank];
|
||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? configuration))
|
||||
{
|
||||
configuration.Rank = rank + 1;
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
// Persist all the rank changes in a single save, so that the reorder is applied atomically.
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#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(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginIds)
|
||||
.NotNull()
|
||||
.WithError(Errors.Plugins.PluginIdsListCannotBeNull)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdsListCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Command for enabling or disabling an artwork provider for a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose artwork provider is enabled or disabled.</param>
|
||||
/// <param name="PluginId">The unique identifier of the plugin providing the artwork.</param>
|
||||
/// <param name="IsEnabled">Whether the artwork provider should be enabled for the media library.</param>
|
||||
public record SetLibraryArtworkProviderEnabledCommand(
|
||||
Guid LibraryId,
|
||||
Guid PluginId,
|
||||
bool IsEnabled
|
||||
) : ICommand;
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to enable or disable an artwork provider for a media library.
|
||||
/// </summary>
|
||||
public class SetLibraryArtworkProviderEnabledCommandHandler : ICommandHandler<SetLibraryArtworkProviderEnabledCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<SetLibraryArtworkProviderEnabledCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public SetLibraryArtworkProviderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<SetLibraryArtworkProviderEnabledCommand> validator)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to enable or disable an artwork provider for a media library.
|
||||
/// </summary>
|
||||
/// <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="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<Success>> HandleAsync(SetLibraryArtworkProviderEnabledCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// Admins can configure the artwork providers of any library; for everyone else, only their own libraries.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// Look up the configuration of this provider for the library, so that an existing one is toggled instead of duplicated.
|
||||
Result<LibraryArtworkProviderConfigurationEntity?> getConfigurationResult = await _unitOfWork.ArtworkProviderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsFailure)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
LibraryArtworkProviderConfigurationEntity configuration;
|
||||
if (getConfigurationResult.Value is not null)
|
||||
{
|
||||
// The provider is already configured for the library, so only its enabled state changes, keeping its existing rank in the display order.
|
||||
configuration = getConfigurationResult.Value;
|
||||
configuration.IsEnabled = command.IsEnabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute the rank to assign to the new configuration, appending it after the existing ones.
|
||||
Result<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.ArtworkProviderConfigurationRepository.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 LibraryArtworkProviderConfigurationEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = command.LibraryId,
|
||||
PluginId = command.PluginId,
|
||||
IsEnabled = command.IsEnabled,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
|
||||
// Insert the new configuration, or update the existing one, and persist the change.
|
||||
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="SetLibraryArtworkProviderEnabledCommand"/>.
|
||||
/// </summary>
|
||||
public class SetLibraryArtworkProviderEnabledCommandValidator : AbstractValidator<SetLibraryArtworkProviderEnabledCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public SetLibraryArtworkProviderEnabledCommandValidator()
|
||||
{
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Command for enabling or disabling a book reader for a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose book reader is enabled or disabled.</param>
|
||||
/// <param name="PluginId">The unique identifier of the plugin providing the book reader.</param>
|
||||
/// <param name="IsEnabled">Whether the book reader should be enabled for the media library.</param>
|
||||
public record SetLibraryBookReaderEnabledCommand(
|
||||
Guid LibraryId,
|
||||
Guid PluginId,
|
||||
bool IsEnabled
|
||||
) : ICommand;
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Reading;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to enable or disable a book reader for a media library.
|
||||
/// </summary>
|
||||
public class SetLibraryBookReaderEnabledCommandHandler : ICommandHandler<SetLibraryBookReaderEnabledCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IBookReaderEnablementCache _enablementCache;
|
||||
private readonly IValidator<SetLibraryBookReaderEnabledCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryBookReaderEnabledCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="enablementCache">Injected cache of whether the book reader of a plugin is enabled for a media library.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public SetLibraryBookReaderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReaderEnablementCache enablementCache, IUnitOfWork unitOfWork, IValidator<SetLibraryBookReaderEnabledCommand> validator)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_enablementCache = enablementCache;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to enable or disable a book reader for a media library.
|
||||
/// </summary>
|
||||
/// <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="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<Success>> HandleAsync(SetLibraryBookReaderEnabledCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// Admins can configure the book readers of any library; for everyone else, only their own libraries.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<LibraryBookReaderConfigurationEntity?> getConfigurationResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsFailure)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
LibraryBookReaderConfigurationEntity configuration;
|
||||
if (getConfigurationResult.Value is not null)
|
||||
{
|
||||
configuration = getConfigurationResult.Value;
|
||||
configuration.IsEnabled = command.IsEnabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
configuration = new LibraryBookReaderConfigurationEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = command.LibraryId,
|
||||
PluginId = command.PluginId,
|
||||
IsEnabled = command.IsEnabled,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
// The reading service caches the enablement of a reader, because it consults it on every request; the cache is invalidated here,
|
||||
// so that disabling a reader cuts access to its books immediately, without waiting for the cache to expire.
|
||||
_enablementCache.Invalidate(command.LibraryId, command.PluginId);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="SetLibraryBookReaderEnabledCommand"/>.
|
||||
/// </summary>
|
||||
public class SetLibraryBookReaderEnabledCommandValidator : AbstractValidator<SetLibraryBookReaderEnabledCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryBookReaderEnabledCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public SetLibraryBookReaderEnabledCommandValidator()
|
||||
{
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
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
|
||||
) : ICommand;
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#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 : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<SetLibraryMetadataProviderEnabledCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public SetLibraryMetadataProviderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<SetLibraryMetadataProviderEnabledCommand> validator)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to enable or disable a metadata provider for a media library.
|
||||
/// </summary>
|
||||
/// <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="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<Success>> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// Admins can configure the metadata providers of any library; for everyone else, only their own libraries.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// Look up the configuration of this provider for the library, so that an existing one is toggled instead of duplicated.
|
||||
Result<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsFailure)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
LibraryMetadataProviderConfigurationEntity configuration;
|
||||
if (getConfigurationResult.Value is not null)
|
||||
{
|
||||
// The provider is already configured for the library, so only its enabled state changes, keeping its existing rank in the display order.
|
||||
configuration = getConfigurationResult.Value;
|
||||
configuration.IsEnabled = command.IsEnabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute the rank to assign to the new configuration, appending it after the existing ones.
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.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
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = command.LibraryId,
|
||||
PluginId = command.PluginId,
|
||||
IsEnabled = command.IsEnabled,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
|
||||
// Insert the new configuration, or update the existing one, and persist the change.
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#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(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.PluginId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the artwork providers available for a media library type.
|
||||
/// </summary>
|
||||
/// <param name="LibraryType">The media library type whose available artwork providers are retrieved.</param>
|
||||
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||
public record GetLibraryTypeArtworkProvidersQuery(
|
||||
string? LibraryType
|
||||
) : IQuery;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the artwork providers available for a media library type.
|
||||
/// </summary>
|
||||
public class GetLibraryTypeArtworkProvidersQueryHandler : IQueryHandler<GetLibraryTypeArtworkProvidersQuery, Result<IReadOnlyList<LibraryArtworkProviderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
|
||||
private readonly IValidator<GetLibraryTypeArtworkProvidersQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryTypeArtworkProvidersQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetLibraryTypeArtworkProvidersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator<GetLibraryTypeArtworkProvidersQuery> validator)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_providerConfigurationStore = providerConfigurationStore;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the artwork providers available for a media library type.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryArtworkProviderResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<LibraryArtworkProviderResponse>>> HandleAsync(GetLibraryTypeArtworkProvidersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
if (_currentUserService.UserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
LibraryType libraryType = Enum.Parse<LibraryType>(query.LibraryType!, ignoreCase: true);
|
||||
|
||||
// Build a plugin name lookup from the detected plugins, so that each provider is returned with its display name.
|
||||
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsFailure)
|
||||
return getPluginsResult.Errors;
|
||||
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||
|
||||
// The providers are returned the way a new media library of this type is configured with them: disabled, and ranked in alphabetical order.
|
||||
IReadOnlyList<Guid> pluginIds = _providerConfigurationStore.GetSupportedArtworkProviderPluginIds(libraryType);
|
||||
return pluginIds
|
||||
.Select((pluginId, index) => new LibraryArtworkProviderResponse(pluginId, pluginNames.GetValueOrDefault(pluginId) ?? string.Empty, IsEnabled: false, Rank: index + 1))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetLibraryTypeArtworkProvidersQuery"/>.
|
||||
/// </summary>
|
||||
public class GetLibraryTypeArtworkProvidersQueryValidator : AbstractValidator<GetLibraryTypeArtworkProvidersQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryTypeArtworkProvidersQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetLibraryTypeArtworkProvidersQueryValidator()
|
||||
{
|
||||
RuleFor(query => query.LibraryType)
|
||||
.NotNull()
|
||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||
.IsInEnum<GetLibraryTypeArtworkProvidersQuery, LibraryType>()
|
||||
.WithError(Errors.Library.UnknownLibraryType);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the book readers available for a media library type.
|
||||
/// </summary>
|
||||
/// <param name="LibraryType">The media library type whose available book readers are retrieved.</param>
|
||||
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||
public record GetLibraryTypeBookReadersQuery(
|
||||
string? LibraryType
|
||||
) : IQuery;
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Reading;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the book readers available for a media library type.
|
||||
/// </summary>
|
||||
public class GetLibraryTypeBookReadersQueryHandler : IQueryHandler<GetLibraryTypeBookReadersQuery, Result<IReadOnlyList<LibraryBookReaderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
|
||||
private readonly IBookReaderRegistry _bookReaderRegistry;
|
||||
private readonly IValidator<GetLibraryTypeBookReadersQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryTypeBookReadersQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
|
||||
/// <param name="bookReaderRegistry">Injected registry of the book readers provided by the loaded plugins.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetLibraryTypeBookReadersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IBookReaderRegistry bookReaderRegistry, IUnitOfWork unitOfWork, IValidator<GetLibraryTypeBookReadersQuery> validator)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_providerConfigurationStore = providerConfigurationStore;
|
||||
_bookReaderRegistry = bookReaderRegistry;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the book readers available for a media library type.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryBookReaderResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<LibraryBookReaderResponse>>> HandleAsync(GetLibraryTypeBookReadersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
if (_currentUserService.UserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
LibraryType libraryType = Enum.Parse<LibraryType>(query.LibraryType!, ignoreCase: true);
|
||||
|
||||
// Build a plugin name lookup from the detected plugins, so that each reader is returned with its display name.
|
||||
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsFailure)
|
||||
return getPluginsResult.Errors;
|
||||
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||
|
||||
IReadOnlyDictionary<Guid, IReadOnlyList<string>> supportedExtensionsByPluginId = _bookReaderRegistry.GetSupportedExtensionsByPluginId();
|
||||
|
||||
// The readers are returned the way a new media library of this type is configured with them: disabled, in alphabetical order.
|
||||
IReadOnlyList<Guid> pluginIds = _providerConfigurationStore.GetSupportedBookReaderPluginIds(libraryType);
|
||||
return pluginIds
|
||||
.Select(pluginId => new LibraryBookReaderResponse(
|
||||
pluginId,
|
||||
pluginNames.GetValueOrDefault(pluginId) ?? string.Empty,
|
||||
supportedExtensionsByPluginId.GetValueOrDefault(pluginId) ?? [],
|
||||
IsEnabled: false))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetLibraryTypeBookReadersQuery"/>.
|
||||
/// </summary>
|
||||
public class GetLibraryTypeBookReadersQueryValidator : AbstractValidator<GetLibraryTypeBookReadersQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryTypeBookReadersQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetLibraryTypeBookReadersQueryValidator()
|
||||
{
|
||||
RuleFor(query => query.LibraryType)
|
||||
.NotNull()
|
||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||
.IsInEnum<GetLibraryTypeBookReadersQuery, LibraryType>()
|
||||
.WithError(Errors.Library.UnknownLibraryType);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the metadata providers available for a media library type.
|
||||
/// </summary>
|
||||
/// <param name="LibraryType">The media library type whose available metadata providers are retrieved.</param>
|
||||
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||
public record GetLibraryTypeMetadataProvidersQuery(
|
||||
string? LibraryType
|
||||
) : IQuery;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the metadata providers available for a media library type.
|
||||
/// </summary>
|
||||
public class GetLibraryTypeMetadataProvidersQueryHandler : IQueryHandler<GetLibraryTypeMetadataProvidersQuery, Result<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
|
||||
private readonly IValidator<GetLibraryTypeMetadataProvidersQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryTypeMetadataProvidersQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetLibraryTypeMetadataProvidersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator<GetLibraryTypeMetadataProvidersQuery> validator)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_providerConfigurationStore = providerConfigurationStore;
|
||||
_unitOfWork = unitOfWork;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the metadata providers available for a media library type.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryTypeMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
if (_currentUserService.UserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
LibraryType libraryType = Enum.Parse<LibraryType>(query.LibraryType!, ignoreCase: true);
|
||||
|
||||
// Build a plugin name lookup from the detected plugins, so that each provider is returned with its display name.
|
||||
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsFailure)
|
||||
return getPluginsResult.Errors;
|
||||
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||
|
||||
// The providers are returned the way a new media library of this type is configured with them: disabled, and ranked in alphabetical order.
|
||||
IReadOnlyList<Guid> pluginIds = _providerConfigurationStore.GetSupportedMetadataProviderPluginIds(libraryType);
|
||||
return pluginIds
|
||||
.Select((pluginId, index) => new LibraryMetadataProviderResponse(pluginId, pluginNames.GetValueOrDefault(pluginId) ?? string.Empty, IsEnabled: false, Rank: index + 1))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetLibraryTypeMetadataProvidersQuery"/>.
|
||||
/// </summary>
|
||||
public class GetLibraryTypeMetadataProvidersQueryValidator : AbstractValidator<GetLibraryTypeMetadataProvidersQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryTypeMetadataProvidersQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetLibraryTypeMetadataProvidersQueryValidator()
|
||||
{
|
||||
RuleFor(query => query.LibraryType)
|
||||
.NotNull()
|
||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||
.IsInEnum<GetLibraryTypeMetadataProvidersQuery, LibraryType>()
|
||||
.WithError(Errors.Library.UnknownLibraryType);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user