diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryProviderSelectionDto.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryProviderSelectionDto.cs
new file mode 100644
index 00000000..cefd576f
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryProviderSelectionDto.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaLibrary.Management;
+
+///
+/// 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.
+///
+/// The Id of the plugin providing the metadata provider, artwork provider or book reader.
+/// 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.
+[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
+public record LibraryProviderSelectionDto(
+ Guid PluginId,
+ bool? IsEnabled
+);
diff --git a/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs b/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs
index 3f911baa..444cc400 100644
--- a/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs
@@ -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;
///
-/// 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.
///
public interface IMediaLibraryProviderConfigurationStore
{
@@ -24,25 +25,18 @@ public interface IMediaLibraryProviderConfigurationStore
Task>> GetConfigurationsAsync(Guid libraryId, CancellationToken cancellationToken);
///
- /// 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 .
///
+ ///
+ /// 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.
+ ///
/// The Id of the media library whose provider configurations are ensured.
/// The type of the media library, used to determine the plugins whose providers apply.
/// Cancellation token that can be used to stop the execution.
/// An representing either a successful operation, or an error.
Task> EnsureProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
- ///
- /// Replaces the provider configurations of the media library identified by so that they
- /// match the plugins supporting the provided library type.
- ///
- /// The Id of the media library whose provider configurations are reconciled.
- /// The type of the media library, used to determine the plugins whose providers apply.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful operation, or an error.
- Task> ReconcileProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
-
///
/// Deletes all the provider configurations of the media library identified by .
///
@@ -60,36 +54,52 @@ public interface IMediaLibraryProviderConfigurationStore
Task> RemoveProviderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
///
- /// 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 .
+ /// Makes the provider and book reader configurations of the media library identified by match the plugins supporting the provided library type, and applies the choices made for them.
///
- /// The Id of the media library whose book reader configurations are ensured.
- /// The type of the media library, used to determine the plugins whose book readers apply.
+ ///
+ /// 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 leaves that kind of configuration untouched, unless
+ /// is , 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.
+ ///
+ /// The Id of the media library whose provider and book reader configurations are configured.
+ /// The type of the media library, used to determine the plugins whose providers and book readers apply.
+ /// The choices made for the metadata providers, in the order in which they are tried.
+ /// The choices made for the artwork providers, in the order in which they are tried.
+ /// The choices made for the book readers.
+ /// Whether the kinds of configuration whose list of choices is are reconciled with the library type, which is needed when the
+ /// library is new or its type changed.
/// Cancellation token that can be used to stop the execution.
- /// An representing either a successful operation, or an error.
- Task> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
+ /// An representing either a successful operation, or an error when a choice names a plugin that does not support the library type.
+ Task> ConfigureProvidersAsync(
+ Guid libraryId,
+ LibraryType libraryType,
+ IReadOnlyList? metadataProviders,
+ IReadOnlyList? artworkProviders,
+ IReadOnlyList? bookReaders,
+ bool shouldReconcileOmittedKinds,
+ CancellationToken cancellationToken);
///
- /// Replaces the book reader configurations of the media library identified by 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.
///
- /// The Id of the media library whose book reader configurations are reconciled.
- /// The type of the media library, used to determine the plugins whose book readers apply.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful operation, or an error.
- Task> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
+ /// The type of the media library the metadata providers must support.
+ /// The Ids of the plugins providing metadata for the library type.
+ IReadOnlyList GetSupportedMetadataProviderPluginIds(LibraryType libraryType);
///
- /// Deletes all the book reader configurations of the media library identified by .
+ /// Gets the Ids of the loaded plugins that provide artwork for the provided library type, ordered alphabetically by plugin name.
///
- /// The Id of the media library whose book reader configurations are deleted.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful operation, or an error.
- Task> RemoveBookReaderConfigurationsForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
+ /// The type of the media library the artwork providers must support.
+ /// The Ids of the plugins providing artwork for the library type.
+ IReadOnlyList GetSupportedArtworkProviderPluginIds(LibraryType libraryType);
///
- /// Deletes all the book reader configurations referencing the plugin identified by .
+ /// Gets the Ids of the loaded plugins that provide a book reader for the provided library type, ordered alphabetically by plugin name.
///
- /// The Id of the plugin whose book reader configurations are deleted.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful operation, or an error.
- Task> RemoveBookReaderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
+ /// The type of the media library the book readers must support.
+ /// The Ids of the plugins providing a book reader for the library type.
+ IReadOnlyList GetSupportedBookReaderPluginIds(LibraryType libraryType);
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs
index 0c62bc02..b9044904 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs
@@ -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
///
/// Converts to .
///
+ ///
+ /// A path template part that is is converted to a part without a kind, and a provider or book reader choice that is 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.
+ ///
/// The request to be converted.
/// The converted command.
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()
);
}
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs
index 6ab4c212..75add9b6 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs
@@ -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
///
/// Converts to .
///
+ ///
+ /// A path template part that is is converted to a part without a kind, and a provider or book reader choice that is 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.
+ ///
/// The request to be converted.
/// The converted command.
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()
);
}
}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeArtworkProvidersRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeArtworkProvidersRequestMapping.cs
new file mode 100644
index 00000000..73e2945c
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeArtworkProvidersRequestMapping.cs
@@ -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;
+
+///
+/// Extension methods for converting .
+///
+public static class GetLibraryTypeArtworkProvidersRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetLibraryTypeArtworkProvidersQuery ToQuery(this GetLibraryTypeArtworkProvidersRequest request)
+ {
+ return new GetLibraryTypeArtworkProvidersQuery(
+ request.LibraryType
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeBookReadersRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeBookReadersRequestMapping.cs
new file mode 100644
index 00000000..f299d721
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeBookReadersRequestMapping.cs
@@ -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;
+
+///
+/// Extension methods for converting .
+///
+public static class GetLibraryTypeBookReadersRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetLibraryTypeBookReadersQuery ToQuery(this GetLibraryTypeBookReadersRequest request)
+ {
+ return new GetLibraryTypeBookReadersQuery(
+ request.LibraryType
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeMetadataProvidersRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeMetadataProvidersRequestMapping.cs
new file mode 100644
index 00000000..31826085
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryTypeMetadataProvidersRequestMapping.cs
@@ -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;
+
+///
+/// Extension methods for converting .
+///
+public static class GetLibraryTypeMetadataProvidersRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetLibraryTypeMetadataProvidersQuery ToQuery(this GetLibraryTypeMetadataProvidersRequest request)
+ {
+ return new GetLibraryTypeMetadataProvidersQuery(
+ request.LibraryType
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/ReorderLibraryArtworkProvidersRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/ReorderLibraryArtworkProvidersRequestMapping.cs
deleted file mode 100644
index 7b0ab2fc..00000000
--- a/src/Lumina.Application/Common/Mapping/Plugins/ReorderLibraryArtworkProvidersRequestMapping.cs
+++ /dev/null
@@ -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;
-
-///
-/// Extension methods for converting .
-///
-public static class ReorderLibraryArtworkProvidersRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted command.
- public static ReorderLibraryArtworkProvidersCommand ToCommand(this ReorderLibraryArtworkProvidersRequest request)
- {
- return new ReorderLibraryArtworkProvidersCommand(
- LibraryId: request.LibraryId,
- PluginIds: request.PluginIds
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/ReorderLibraryMetadataProvidersRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/ReorderLibraryMetadataProvidersRequestMapping.cs
deleted file mode 100644
index 6857df1e..00000000
--- a/src/Lumina.Application/Common/Mapping/Plugins/ReorderLibraryMetadataProvidersRequestMapping.cs
+++ /dev/null
@@ -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;
-
-///
-/// Extension methods for converting .
-///
-public static class ReorderLibraryMetadataProvidersRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted command.
- public static ReorderLibraryMetadataProvidersCommand ToCommand(this ReorderLibraryMetadataProvidersRequest request)
- {
- return new ReorderLibraryMetadataProvidersCommand(request.LibraryId, request.PluginIds);
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryArtworkProviderEnabledRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryArtworkProviderEnabledRequestMapping.cs
deleted file mode 100644
index 4494aeb8..00000000
--- a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryArtworkProviderEnabledRequestMapping.cs
+++ /dev/null
@@ -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;
-
-///
-/// Extension methods for converting .
-///
-public static class SetLibraryArtworkProviderEnabledRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted command.
- public static SetLibraryArtworkProviderEnabledCommand ToCommand(this SetLibraryArtworkProviderEnabledRequest request)
- {
- return new SetLibraryArtworkProviderEnabledCommand(
- LibraryId: request.LibraryId,
- PluginId: request.PluginId,
- IsEnabled: request.IsEnabled
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryBookReaderEnabledRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryBookReaderEnabledRequestMapping.cs
deleted file mode 100644
index 727601ca..00000000
--- a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryBookReaderEnabledRequestMapping.cs
+++ /dev/null
@@ -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;
-
-///
-/// Extension methods for converting .
-///
-public static class SetLibraryBookReaderEnabledRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted command.
- public static SetLibraryBookReaderEnabledCommand ToCommand(this SetLibraryBookReaderEnabledRequest request)
- {
- return new SetLibraryBookReaderEnabledCommand(
- request.LibraryId,
- request.PluginId,
- request.IsEnabled
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryMetadataProviderEnabledRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryMetadataProviderEnabledRequestMapping.cs
deleted file mode 100644
index a0b46032..00000000
--- a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryMetadataProviderEnabledRequestMapping.cs
+++ /dev/null
@@ -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;
-
-///
-/// Extension methods for converting .
-///
-public static class SetLibraryMetadataProviderEnabledRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted command.
- public static SetLibraryMetadataProviderEnabledCommand ToCommand(this SetLibraryMetadataProviderEnabledRequest request)
- {
- return new SetLibraryMetadataProviderEnabledCommand(request.LibraryId, request.PluginId, request.IsEnabled);
- }
-}
diff --git a/src/Lumina.Application/Core/Favorites/Commands/RemoveFavorite/RemoveFavoriteCommandValidator.cs b/src/Lumina.Application/Core/Favorites/Commands/RemoveFavorite/RemoveFavoriteCommandValidator.cs
index b6a46775..dd9a9998 100644
--- a/src/Lumina.Application/Core/Favorites/Commands/RemoveFavorite/RemoveFavoriteCommandValidator.cs
+++ b/src/Lumina.Application/Core/Favorites/Commands/RemoveFavorite/RemoveFavoriteCommandValidator.cs
@@ -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 command.MediaKind)
- .Must(mediaKind => Enum.GetNames()
- .Where(mediaKindName => !string.Equals(mediaKindName, nameof(FavoriteMediaKind.None), StringComparison.Ordinal))
- .Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
+ .IsInEnum()
+ .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);
diff --git a/src/Lumina.Application/Core/MediaConsumption/Commands/StartConsumption/StartConsumptionCommandValidator.cs b/src/Lumina.Application/Core/MediaConsumption/Commands/StartConsumption/StartConsumptionCommandValidator.cs
index f12a2dab..d39cfe27 100644
--- a/src/Lumina.Application/Core/MediaConsumption/Commands/StartConsumption/StartConsumptionCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaConsumption/Commands/StartConsumption/StartConsumptionCommandValidator.cs
@@ -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 command.MediaKind)
- .Must(mediaKind => Enum.GetNames().Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
+ .IsInEnum()
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
diff --git a/src/Lumina.Application/Core/MediaConsumption/Queries/GetResumePoint/GetResumePointQueryValidator.cs b/src/Lumina.Application/Core/MediaConsumption/Queries/GetResumePoint/GetResumePointQueryValidator.cs
index 389ae690..64fbe268 100644
--- a/src/Lumina.Application/Core/MediaConsumption/Queries/GetResumePoint/GetResumePointQueryValidator.cs
+++ b/src/Lumina.Application/Core/MediaConsumption/Queries/GetResumePoint/GetResumePointQueryValidator.cs
@@ -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 query.MediaKind)
- .Must(mediaKind => Enum.GetNames().Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
+ .IsInEnum()
.When(query => query.MediaKind is not null && query.MediaKind.Length > 0)
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs
index 6b013e07..92600e28 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs
@@ -22,6 +22,9 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
/// Whether the consumption progress of the media library items should be tracked, or not. When absent, the default of the library type is used.
/// 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.
/// The ordered parts of the template describing the structure of the media library on disk.
+/// 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.
+/// 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.
+/// 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.
[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;
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs
index 1a4cf50b..2f6232dd 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs
@@ -114,7 +114,7 @@ public class AddLibraryCommandHandler : ICommandHandler(command.LibraryType!);
+ LibraryType libraryType = Enum.Parse(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 insertLibraryResult = await _unitOfWork.LibraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (insertLibraryResult.IsFailure)
return insertLibraryResult.Errors;
- Result ensureProviderConfigurationsResult = await _providerConfigurationStore.EnsureProviderConfigurationsAsync(
- createLibraryResult.Value.Id.Value, libraryType, cancellationToken).ConfigureAwait(false);
- if (ensureProviderConfigurationsResult.IsFailure)
- return ensureProviderConfigurationsResult.Errors;
+ Result 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 saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
if (saveChangesResult.IsFailure)
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs
index d5974c69..beb7f1c6 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs
@@ -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
RuleFor(command => command.LibraryType)
.NotNull()
.WithError(Errors.Library.LibraryTypeCannotBeNull)
- .Must(libraryType => Enum.TryParse(libraryType, out _))
+ .IsInEnum()
.WithError(Errors.Library.UnknownLibraryType);
RuleFor(command => command.ContentLocations)
@@ -61,5 +62,32 @@ public class AddLibraryCommandValidator : AbstractValidator
.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);
}
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs
index ae7b4e06..81572f86 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs
@@ -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(
- 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(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.
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs
index 66819bd4..5ad99baf 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs
@@ -11,7 +11,6 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
/// Command for updating a media library.
///
/// The unique identifier of the media library.
-/// The unique identifier of the user owning the media library.
/// The title of the media library.
/// The type of the media library.
/// The file system paths of the directories where the media library elements are located.
@@ -25,10 +24,12 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
/// Whether the consumption progress of the media library items should be tracked, or not. When absent, the stored value is kept.
/// 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.
/// The ordered parts of the template describing the structure of the media library on disk.
+/// 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.
+/// 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.
+/// 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.
[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;
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs
index b77a417c..84209f82 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs
@@ -105,6 +105,16 @@ public class UpdateLibraryCommandHandler : ICommandHandler(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(
- userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false);
- if (!hasManagePermission && !canAccessLibrary)
- return ApplicationErrors.Authorization.NotAuthorized;
-
// Create a domain library object.
- LibraryType newLibraryType = Enum.Parse(command.LibraryType!);
+ LibraryType newLibraryType = Enum.Parse(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 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 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 reconcileResult = await _providerConfigurationStore.ReconcileProviderConfigurationsAsync(command.Id, newLibraryType, cancellationToken).ConfigureAwait(false);
- if (reconcileResult.IsFailure)
- return reconcileResult.Errors;
+ Result configureProvidersResult = await _providerConfigurationStore.ConfigureProvidersAsync(
+ command.Id, newLibraryType, command.MetadataProviders, command.ArtworkProviders, command.BookReaders, isLibraryTypeChanged, cancellationToken).ConfigureAwait(false);
+ if (configureProvidersResult.IsFailure)
+ return configureProvidersResult.Errors;
}
Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
if (saveChangesResult.IsFailure)
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs
index d0a2c721..70d8deff 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs
@@ -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 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, out _))
+ .IsInEnum()
.WithError(Errors.Library.UnknownLibraryType);
RuleFor(command => command.ContentLocations)
@@ -73,5 +68,32 @@ public class UpdateLibraryCommandValidator : AbstractValidator !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);
}
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs
index ac64fcec..b39ec76d 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs
@@ -41,19 +41,19 @@ public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler
public Task> 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>(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.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 parts =
[
.. catalog.GetPartDefinitions().Select(definition => new LibraryPathPartDefinitionResponse(
@@ -62,7 +62,7 @@ public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler defaultTemplateParts =
[
.. catalog.GetDefaultTemplate().Parts.Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional))
diff --git a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommand.cs
deleted file mode 100644
index a202a355..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommand.cs
+++ /dev/null
@@ -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;
-
-///
-/// Command for reordering the artwork providers of a media library.
-///
-/// The Id of the media library whose artwork providers are reordered.
-/// The plugin Ids in the new order, from highest to lowest rank.
-public record ReorderLibraryArtworkProvidersCommand(
- Guid LibraryId,
- IReadOnlyList PluginIds
-) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommandHandler.cs
deleted file mode 100644
index 8c713a6b..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommandHandler.cs
+++ /dev/null
@@ -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;
-
-///
-/// Handler for the command to reorder the artwork providers of a media library.
-///
-public class ReorderLibraryArtworkProvidersCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly IAuthorizationService _authorizationService;
- private readonly ICurrentUserService _currentUserService;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected service for authorization related functionality.
- /// Injected service to retrieve the current user information.
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected validator for application validation rules.
- public ReorderLibraryArtworkProvidersCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator)
- {
- _authorizationService = authorizationService;
- _currentUserService = currentUserService;
- _unitOfWork = unitOfWork;
- _validator = validator;
- }
-
- ///
- /// Handles the command to reorder the artwork providers of a media library.
- ///
- /// The request to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An representing either a successful operation, or an error.
- ///
- public async Task> HandleAsync(ReorderLibraryArtworkProvidersCommand command, CancellationToken cancellationToken)
- {
- List 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(
- 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> 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 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 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 saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
- return Result.Success;
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommandValidator.cs
deleted file mode 100644
index 770f3f31..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryArtworkProviders/ReorderLibraryArtworkProvidersCommandValidator.cs
+++ /dev/null
@@ -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;
-
-///
-/// Validates the needed validation rules for .
-///
-public class ReorderLibraryArtworkProvidersCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- 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);
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommand.cs
deleted file mode 100644
index a1ab58c2..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommand.cs
+++ /dev/null
@@ -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;
-
-///
-/// Command for reordering the metadata providers of a media library.
-///
-/// The Id of the media library whose metadata providers are reordered.
-/// The plugin Ids in the new order, from highest to lowest rank.
-public record ReorderLibraryMetadataProvidersCommand(
- Guid LibraryId,
- IReadOnlyList PluginIds
-) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommandHandler.cs
deleted file mode 100644
index 3b3133c8..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommandHandler.cs
+++ /dev/null
@@ -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;
-
-///
-/// Handler for the command to reorder the metadata providers of a media library.
-///
-public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly IAuthorizationService _authorizationService;
- private readonly ICurrentUserService _currentUserService;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected service for authorization related functionality.
- /// Injected service to retrieve the current user information.
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected validator for application validation rules.
- public ReorderLibraryMetadataProvidersCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator)
- {
- _authorizationService = authorizationService;
- _currentUserService = currentUserService;
- _unitOfWork = unitOfWork;
- _validator = validator;
- }
-
- ///
- /// Handles the command to reorder the metadata providers of a media library.
- ///
- /// The request to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An representing either a successful operation, or an error.
- ///
- public async Task> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
- {
- List 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(
- 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> 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 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 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 saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
- return Result.Success;
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommandValidator.cs
deleted file mode 100644
index 95c01884..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/ReorderLibraryMetadataProviders/ReorderLibraryMetadataProvidersCommandValidator.cs
+++ /dev/null
@@ -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;
-
-///
-/// Validates the needed validation rules for .
-///
-public class ReorderLibraryMetadataProvidersCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- 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);
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommand.cs
deleted file mode 100644
index e4acf111..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommand.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
-
-///
-/// Command for enabling or disabling an artwork provider for a media library.
-///
-/// The Id of the media library whose artwork provider is enabled or disabled.
-/// The unique identifier of the plugin providing the artwork.
-/// Whether the artwork provider should be enabled for the media library.
-public record SetLibraryArtworkProviderEnabledCommand(
- Guid LibraryId,
- Guid PluginId,
- bool IsEnabled
-) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommandHandler.cs
deleted file mode 100644
index 09b304db..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommandHandler.cs
+++ /dev/null
@@ -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;
-
-///
-/// Handler for the command to enable or disable an artwork provider for a media library.
-///
-public class SetLibraryArtworkProviderEnabledCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly IAuthorizationService _authorizationService;
- private readonly ICurrentUserService _currentUserService;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected service for authorization related functionality.
- /// Injected service to retrieve the current user information.
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected validator for application validation rules.
- public SetLibraryArtworkProviderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator)
- {
- _authorizationService = authorizationService;
- _currentUserService = currentUserService;
- _unitOfWork = unitOfWork;
- _validator = validator;
- }
-
- ///
- /// Handles the command to enable or disable an artwork provider for a media library.
- ///
- /// The request to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An representing either a successful operation, or an error.
- ///
- public async Task> HandleAsync(SetLibraryArtworkProviderEnabledCommand command, CancellationToken cancellationToken)
- {
- List 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(
- 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 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> 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 upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
- if (upsertResult.IsFailure)
- return upsertResult.Errors;
-
- Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
- return Result.Success;
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommandValidator.cs
deleted file mode 100644
index 040a486f..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryArtworkProviderEnabled/SetLibraryArtworkProviderEnabledCommandValidator.cs
+++ /dev/null
@@ -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;
-
-///
-/// Validates the needed validation rules for .
-///
-public class SetLibraryArtworkProviderEnabledCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- 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);
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommand.cs
deleted file mode 100644
index a40b4e93..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommand.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
-
-///
-/// Command for enabling or disabling a book reader for a media library.
-///
-/// The Id of the media library whose book reader is enabled or disabled.
-/// The unique identifier of the plugin providing the book reader.
-/// Whether the book reader should be enabled for the media library.
-public record SetLibraryBookReaderEnabledCommand(
- Guid LibraryId,
- Guid PluginId,
- bool IsEnabled
-) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandHandler.cs
deleted file mode 100644
index 6ff5d6c9..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandHandler.cs
+++ /dev/null
@@ -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;
-
-///
-/// Handler for the command to enable or disable a book reader for a media library.
-///
-public class SetLibraryBookReaderEnabledCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly IAuthorizationService _authorizationService;
- private readonly ICurrentUserService _currentUserService;
- private readonly IBookReaderEnablementCache _enablementCache;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected service for authorization related functionality.
- /// Injected service to retrieve the current user information.
- /// Injected cache of whether the book reader of a plugin is enabled for a media library.
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected validator for application validation rules.
- public SetLibraryBookReaderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReaderEnablementCache enablementCache, IUnitOfWork unitOfWork, IValidator validator)
- {
- _authorizationService = authorizationService;
- _currentUserService = currentUserService;
- _enablementCache = enablementCache;
- _unitOfWork = unitOfWork;
- _validator = validator;
- }
-
- ///
- /// Handles the command to enable or disable a book reader for a media library.
- ///
- /// The request to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An representing either a successful operation, or an error.
- ///
- public async Task> HandleAsync(SetLibraryBookReaderEnabledCommand command, CancellationToken cancellationToken)
- {
- List 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(userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
- if (!canAccessLibrary)
- return ApplicationErrors.Authorization.NotAuthorized;
-
- Result 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 upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
- if (upsertResult.IsFailure)
- return upsertResult.Errors;
- Result 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;
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandValidator.cs
deleted file mode 100644
index 1178b5f9..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandValidator.cs
+++ /dev/null
@@ -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;
-
-///
-/// Validates the needed validation rules for .
-///
-public class SetLibraryBookReaderEnabledCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- public SetLibraryBookReaderEnabledCommandValidator()
- {
- RuleFor(command => command.LibraryId)
- .NotEmpty()
- .WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
-
- RuleFor(command => command.PluginId)
- .NotEmpty()
- .WithError(Errors.Plugins.PluginIdCannotBeEmpty);
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommand.cs
deleted file mode 100644
index c81174c5..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommand.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
-
-///
-/// Command for enabling or disabling a metadata provider for a media library.
-///
-/// The Id of the media library whose metadata provider is enabled or disabled.
-/// The unique identifier of the plugin providing the metadata.
-/// Whether the metadata provider should be enabled for the media library.
-public record SetLibraryMetadataProviderEnabledCommand(
- Guid LibraryId,
- Guid PluginId,
- bool IsEnabled
-) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommandHandler.cs
deleted file mode 100644
index 526852b2..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommandHandler.cs
+++ /dev/null
@@ -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;
-
-///
-/// Handler for the command to enable or disable a metadata provider for a media library.
-///
-public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly IAuthorizationService _authorizationService;
- private readonly ICurrentUserService _currentUserService;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected service for authorization related functionality.
- /// Injected service to retrieve the current user information.
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected validator for application validation rules.
- public SetLibraryMetadataProviderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator)
- {
- _authorizationService = authorizationService;
- _currentUserService = currentUserService;
- _unitOfWork = unitOfWork;
- _validator = validator;
- }
-
- ///
- /// Handles the command to enable or disable a metadata provider for a media library.
- ///
- /// The request to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An representing either a successful operation, or an error.
- ///
- public async Task> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
- {
- List 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(
- 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 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> 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 upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
- if (upsertResult.IsFailure)
- return upsertResult.Errors;
-
- Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
- return Result.Success;
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommandValidator.cs
deleted file mode 100644
index b910702f..00000000
--- a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryMetadataProviderEnabled/SetLibraryMetadataProviderEnabledCommandValidator.cs
+++ /dev/null
@@ -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;
-
-///
-/// Validates the needed validation rules for .
-///
-public class SetLibraryMetadataProviderEnabledCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- 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);
- }
-}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQuery.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQuery.cs
new file mode 100644
index 00000000..ed2691f7
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQuery.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
+
+///
+/// Query for getting the artwork providers available for a media library type.
+///
+/// The media library type whose available artwork providers are retrieved.
+[DebuggerDisplay("LibraryType: {LibraryType}")]
+public record GetLibraryTypeArtworkProvidersQuery(
+ string? LibraryType
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQueryHandler.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQueryHandler.cs
new file mode 100644
index 00000000..92cfe456
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQueryHandler.cs
@@ -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;
+
+///
+/// Handler for the query to get the artwork providers available for a media library type.
+///
+public class GetLibraryTypeArtworkProvidersQueryHandler : IQueryHandler>>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service to retrieve the current user information.
+ /// Injected store of the provider configurations of the media libraries.
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
+ public GetLibraryTypeArtworkProvidersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator validator)
+ {
+ _currentUserService = currentUserService;
+ _providerConfigurationStore = providerConfigurationStore;
+ _unitOfWork = unitOfWork;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the artwork providers available for a media library type.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either a collection of , or an error.
+ ///
+ public async Task>> HandleAsync(GetLibraryTypeArtworkProvidersQuery query, CancellationToken cancellationToken)
+ {
+ List 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(query.LibraryType!, ignoreCase: true);
+
+ // Build a plugin name lookup from the detected plugins, so that each provider is returned with its display name.
+ Result> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
+ if (getPluginsResult.IsFailure)
+ return getPluginsResult.Errors;
+ Dictionary 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 pluginIds = _providerConfigurationStore.GetSupportedArtworkProviderPluginIds(libraryType);
+ return pluginIds
+ .Select((pluginId, index) => new LibraryArtworkProviderResponse(pluginId, pluginNames.GetValueOrDefault(pluginId) ?? string.Empty, IsEnabled: false, Rank: index + 1))
+ .ToList();
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQueryValidator.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQueryValidator.cs
new file mode 100644
index 00000000..53f53134
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeArtworkProviders/GetLibraryTypeArtworkProvidersQueryValidator.cs
@@ -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;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetLibraryTypeArtworkProvidersQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetLibraryTypeArtworkProvidersQueryValidator()
+ {
+ RuleFor(query => query.LibraryType)
+ .NotNull()
+ .WithError(Errors.Library.LibraryTypeCannotBeNull)
+ .IsInEnum()
+ .WithError(Errors.Library.UnknownLibraryType);
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQuery.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQuery.cs
new file mode 100644
index 00000000..aa64b3e8
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQuery.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
+
+///
+/// Query for getting the book readers available for a media library type.
+///
+/// The media library type whose available book readers are retrieved.
+[DebuggerDisplay("LibraryType: {LibraryType}")]
+public record GetLibraryTypeBookReadersQuery(
+ string? LibraryType
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQueryHandler.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQueryHandler.cs
new file mode 100644
index 00000000..1b6fd722
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQueryHandler.cs
@@ -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;
+
+///
+/// Handler for the query to get the book readers available for a media library type.
+///
+public class GetLibraryTypeBookReadersQueryHandler : IQueryHandler>>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
+ private readonly IBookReaderRegistry _bookReaderRegistry;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service to retrieve the current user information.
+ /// Injected store of the provider configurations of the media libraries.
+ /// Injected registry of the book readers provided by the loaded plugins.
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
+ public GetLibraryTypeBookReadersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IBookReaderRegistry bookReaderRegistry, IUnitOfWork unitOfWork, IValidator validator)
+ {
+ _currentUserService = currentUserService;
+ _providerConfigurationStore = providerConfigurationStore;
+ _bookReaderRegistry = bookReaderRegistry;
+ _unitOfWork = unitOfWork;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the book readers available for a media library type.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either a collection of , or an error.
+ ///
+ public async Task>> HandleAsync(GetLibraryTypeBookReadersQuery query, CancellationToken cancellationToken)
+ {
+ List 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(query.LibraryType!, ignoreCase: true);
+
+ // Build a plugin name lookup from the detected plugins, so that each reader is returned with its display name.
+ Result> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
+ if (getPluginsResult.IsFailure)
+ return getPluginsResult.Errors;
+ Dictionary pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
+
+ IReadOnlyDictionary> 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 pluginIds = _providerConfigurationStore.GetSupportedBookReaderPluginIds(libraryType);
+ return pluginIds
+ .Select(pluginId => new LibraryBookReaderResponse(
+ pluginId,
+ pluginNames.GetValueOrDefault(pluginId) ?? string.Empty,
+ supportedExtensionsByPluginId.GetValueOrDefault(pluginId) ?? [],
+ IsEnabled: false))
+ .ToList();
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQueryValidator.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQueryValidator.cs
new file mode 100644
index 00000000..eed752b0
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeBookReaders/GetLibraryTypeBookReadersQueryValidator.cs
@@ -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;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetLibraryTypeBookReadersQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetLibraryTypeBookReadersQueryValidator()
+ {
+ RuleFor(query => query.LibraryType)
+ .NotNull()
+ .WithError(Errors.Library.LibraryTypeCannotBeNull)
+ .IsInEnum()
+ .WithError(Errors.Library.UnknownLibraryType);
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQuery.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQuery.cs
new file mode 100644
index 00000000..a7e250c2
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQuery.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
+
+///
+/// Query for getting the metadata providers available for a media library type.
+///
+/// The media library type whose available metadata providers are retrieved.
+[DebuggerDisplay("LibraryType: {LibraryType}")]
+public record GetLibraryTypeMetadataProvidersQuery(
+ string? LibraryType
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQueryHandler.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQueryHandler.cs
new file mode 100644
index 00000000..3b867d57
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQueryHandler.cs
@@ -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;
+
+///
+/// Handler for the query to get the metadata providers available for a media library type.
+///
+public class GetLibraryTypeMetadataProvidersQueryHandler : IQueryHandler>>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service to retrieve the current user information.
+ /// Injected store of the provider configurations of the media libraries.
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
+ public GetLibraryTypeMetadataProvidersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator validator)
+ {
+ _currentUserService = currentUserService;
+ _providerConfigurationStore = providerConfigurationStore;
+ _unitOfWork = unitOfWork;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the metadata providers available for a media library type.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either a collection of , or an error.
+ ///
+ public async Task>> HandleAsync(GetLibraryTypeMetadataProvidersQuery query, CancellationToken cancellationToken)
+ {
+ List 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(query.LibraryType!, ignoreCase: true);
+
+ // Build a plugin name lookup from the detected plugins, so that each provider is returned with its display name.
+ Result> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
+ if (getPluginsResult.IsFailure)
+ return getPluginsResult.Errors;
+ Dictionary 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 pluginIds = _providerConfigurationStore.GetSupportedMetadataProviderPluginIds(libraryType);
+ return pluginIds
+ .Select((pluginId, index) => new LibraryMetadataProviderResponse(pluginId, pluginNames.GetValueOrDefault(pluginId) ?? string.Empty, IsEnabled: false, Rank: index + 1))
+ .ToList();
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQueryValidator.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQueryValidator.cs
new file mode 100644
index 00000000..c727f952
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryTypeMetadataProviders/GetLibraryTypeMetadataProvidersQueryValidator.cs
@@ -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;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetLibraryTypeMetadataProvidersQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetLibraryTypeMetadataProvidersQueryValidator()
+ {
+ RuleFor(query => query.LibraryType)
+ .NotNull()
+ .WithError(Errors.Library.LibraryTypeCannotBeNull)
+ .IsInEnum()
+ .WithError(Errors.Library.UnknownLibraryType);
+ }
+}
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs
index 6daf08ed..0a755dd6 100644
--- a/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs
@@ -11,15 +11,18 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
/// The type of the media library. Required.
/// The file system paths of the directories where the media library elements are located. Required.
/// The path of the image file used as the cover for the library. Optional.
-/// Whether this media library is enabled or not. A disabled media library is never shown or changed. Optional.
-/// Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Optional.
-/// Whether this media library should update the metadata of its elements from the web, or not. Optional.
-/// Whether this media library should copy the downloaded metadata into the media library content locations, or not. Optional.
-/// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional.
-/// Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Optional.
+/// Whether this media library is enabled or not. A disabled media library is never shown or changed. Required.
+/// Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Required.
+/// Whether this media library should update the metadata of its elements from the web, or not. Required.
+/// Whether this media library should copy the downloaded metadata into the media library content locations, or not. Required.
+/// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Required.
+/// Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Required.
/// Whether the consumption progress of the media library items should be tracked, or not. Optional, the default of the library type is used when absent.
/// The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the default of the library type is used when absent.
/// The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.
+/// The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, every provider supported by the library type is added disabled.
+/// The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, every provider supported by the library type is added disabled.
+/// The book readers of the media library, and whether each one is enabled. Optional, every reader supported by the library type is added disabled.
[DebuggerDisplay("Title: {Title}")]
public record AddLibraryRequest(
string? Title,
@@ -34,5 +37,8 @@ public record AddLibraryRequest(
bool IsContentOnSsd,
bool? ShouldTrackConsumptionProgress,
int? CompletionThresholdPercentage,
- LibraryPathTemplatePartRequest[]? PathTemplateParts
+ LibraryPathTemplatePartRequest?[]? PathTemplateParts,
+ LibraryProviderSelectionRequest?[]? MetadataProviders,
+ LibraryProviderSelectionRequest?[]? ArtworkProviders,
+ LibraryProviderSelectionRequest?[]? BookReaders
);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryProviderSelectionRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryProviderSelectionRequest.cs
new file mode 100644
index 00000000..26552e4e
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryProviderSelectionRequest.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaLibrary.Management;
+
+///
+/// Represents the choice made for one metadata provider, artwork provider or book reader of a media library.
+///
+/// The Id of the plugin providing the metadata provider, artwork provider or book reader. Required.
+/// Whether the provider or reader is enabled for the media library. Optional, the stored state is kept when absent, and a provider or reader without a stored state starts disabled.
+[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
+public record LibraryProviderSelectionRequest(
+ Guid PluginId,
+ bool? IsEnabled
+);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs
index 9d4377f2..b1183e6f 100644
--- a/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs
@@ -9,24 +9,25 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
/// Represents a request to update a media library.
///
/// The unique identifier of the media library. Required.
-/// The unique identifier of the user owning the media library. Required.
/// The title of the media library. Required.
/// The type of the media library. Required.
/// The file system paths of the directories where the media library elements are located. Required.
/// The path of the image file used as the cover for the library. Optional.
-/// Whether this media library is enabled or not. A disabled media library is never shown or changed. Optional.
-/// Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Optional.
-/// Whether this media library should update the metadata of its elements from the web, or not. Optional.
-/// Whether this media library should copy the downloaded metadata into the media library content locations, or not.
-/// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional.
-/// Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Optional.
+/// Whether this media library is enabled or not. A disabled media library is never shown or changed. Required.
+/// Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Required.
+/// Whether this media library should update the metadata of its elements from the web, or not. Required.
+/// Whether this media library should copy the downloaded metadata into the media library content locations, or not. Required.
+/// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Required.
+/// Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Required.
/// Whether the consumption progress of the media library items should be tracked, or not. Optional, the stored value is kept when absent.
/// The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the stored value is kept when absent.
/// The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.
+/// The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes.
+/// The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes.
+/// The book readers of the media library, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes.
[DebuggerDisplay("Title: {Title}")]
public record class UpdateLibraryRequest(
Guid Id,
- Guid UserId,
string? Title,
string? LibraryType,
string[]? ContentLocations,
@@ -39,5 +40,8 @@ public record class UpdateLibraryRequest(
bool IsContentOnSsd,
bool? ShouldTrackConsumptionProgress,
int? CompletionThresholdPercentage,
- LibraryPathTemplatePartRequest[]? PathTemplateParts
+ LibraryPathTemplatePartRequest?[]? PathTemplateParts,
+ LibraryProviderSelectionRequest?[]? MetadataProviders,
+ LibraryProviderSelectionRequest?[]? ArtworkProviders,
+ LibraryProviderSelectionRequest?[]? BookReaders
);
diff --git a/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeArtworkProvidersRequest.cs b/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeArtworkProvidersRequest.cs
new file mode 100644
index 00000000..21c66ce0
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeArtworkProvidersRequest.cs
@@ -0,0 +1,14 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Plugins;
+
+///
+/// Represents a request to get the artwork providers available for a media library type.
+///
+/// The media library type whose available artwork providers are retrieved. Required.
+[DebuggerDisplay("LibraryType: {LibraryType}")]
+public sealed record GetLibraryTypeArtworkProvidersRequest(
+ string? LibraryType
+);
diff --git a/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeBookReadersRequest.cs b/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeBookReadersRequest.cs
new file mode 100644
index 00000000..496af117
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeBookReadersRequest.cs
@@ -0,0 +1,14 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Plugins;
+
+///
+/// Represents a request to get the book readers available for a media library type.
+///
+/// The media library type whose available book readers are retrieved. Required.
+[DebuggerDisplay("LibraryType: {LibraryType}")]
+public sealed record GetLibraryTypeBookReadersRequest(
+ string? LibraryType
+);
diff --git a/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeMetadataProvidersRequest.cs b/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeMetadataProvidersRequest.cs
new file mode 100644
index 00000000..8eff614b
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Plugins/GetLibraryTypeMetadataProvidersRequest.cs
@@ -0,0 +1,14 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Plugins;
+
+///
+/// Represents a request to get the metadata providers available for a media library type.
+///
+/// The media library type whose available metadata providers are retrieved. Required.
+[DebuggerDisplay("LibraryType: {LibraryType}")]
+public sealed record GetLibraryTypeMetadataProvidersRequest(
+ string? LibraryType
+);
diff --git a/src/Lumina.Contracts/Requests/Plugins/ReorderLibraryArtworkProvidersRequest.cs b/src/Lumina.Contracts/Requests/Plugins/ReorderLibraryArtworkProvidersRequest.cs
deleted file mode 100644
index 0e0f815c..00000000
--- a/src/Lumina.Contracts/Requests/Plugins/ReorderLibraryArtworkProvidersRequest.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.Plugins;
-
-///
-/// Represents a request to reorder the artwork providers of a media library.
-///
-/// The unique identifier of the media library whose artwork providers are reordered. Required.
-/// The plugin Ids in the new order, from highest to lowest rank. Required.
-[DebuggerDisplay("LibraryId: {LibraryId}")]
-public sealed record ReorderLibraryArtworkProvidersRequest(
- Guid LibraryId,
- IReadOnlyList PluginIds
-);
diff --git a/src/Lumina.Contracts/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs b/src/Lumina.Contracts/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs
deleted file mode 100644
index 24b6021e..00000000
--- a/src/Lumina.Contracts/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.Plugins;
-
-///
-/// Represents a request to reorder the metadata providers of a media library.
-///
-/// The Id of the media library whose metadata providers are reordered. Required.
-/// The plugin Ids in the new order, from highest to lowest rank. Required.
-[DebuggerDisplay("LibraryId: {LibraryId}")]
-public sealed record ReorderLibraryMetadataProvidersRequest(
- Guid LibraryId,
- IReadOnlyList PluginIds
-);
diff --git a/src/Lumina.Contracts/Requests/Plugins/SetLibraryArtworkProviderEnabledRequest.cs b/src/Lumina.Contracts/Requests/Plugins/SetLibraryArtworkProviderEnabledRequest.cs
deleted file mode 100644
index bbfb2b95..00000000
--- a/src/Lumina.Contracts/Requests/Plugins/SetLibraryArtworkProviderEnabledRequest.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.Plugins;
-
-///
-/// Represents a request to enable or disable an artwork provider for a media library.
-///
-/// The unique identifier of the media library whose artwork provider is enabled or disabled. Required.
-/// The unique identifier of the plugin providing the artwork. Required.
-/// Whether the artwork provider should be enabled for the media library. Required.
-[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
-public sealed record SetLibraryArtworkProviderEnabledRequest(
- Guid LibraryId,
- Guid PluginId,
- bool IsEnabled
-);
diff --git a/src/Lumina.Contracts/Requests/Plugins/SetLibraryBookReaderEnabledRequest.cs b/src/Lumina.Contracts/Requests/Plugins/SetLibraryBookReaderEnabledRequest.cs
deleted file mode 100644
index 3392ae17..00000000
--- a/src/Lumina.Contracts/Requests/Plugins/SetLibraryBookReaderEnabledRequest.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.Plugins;
-
-///
-/// Represents a request to enable or disable a book reader for a media library.
-///
-/// The Id of the media library whose book reader is enabled or disabled. Required.
-/// The unique identifier of the plugin providing the book reader. Required.
-/// Whether the book reader should be enabled for the media library. Required.
-[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
-public sealed record SetLibraryBookReaderEnabledRequest(
- Guid LibraryId,
- Guid PluginId,
- bool IsEnabled
-);
diff --git a/src/Lumina.Contracts/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs b/src/Lumina.Contracts/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs
deleted file mode 100644
index 342ec7b7..00000000
--- a/src/Lumina.Contracts/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.Plugins;
-
-///
-/// Represents a request to enable or disable a metadata provider for a media library.
-///
-/// The Id of the media library whose metadata provider is enabled or disabled. Required.
-/// The unique identifier of the plugin providing the metadata. Required.
-/// Whether the metadata provider should be enabled for the media library. Required.
-[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
-public sealed record SetLibraryMetadataProviderEnabledRequest(
- Guid LibraryId,
- Guid PluginId,
- bool IsEnabled
-);
diff --git a/src/Lumina.Contracts/Responses/Plugins/LibraryArtworkProviderResponse.cs b/src/Lumina.Contracts/Responses/Plugins/LibraryArtworkProviderResponse.cs
index c9b01c01..a000754a 100644
--- a/src/Lumina.Contracts/Responses/Plugins/LibraryArtworkProviderResponse.cs
+++ b/src/Lumina.Contracts/Responses/Plugins/LibraryArtworkProviderResponse.cs
@@ -5,12 +5,12 @@ using System;
namespace Lumina.Contracts.Responses.Plugins;
///
-/// Represents an artwork provider configured for a media library.
+/// Represents an artwork provider, either as configured for a media library, or as available for a library type, the way a new library of that type starts.
///
/// The unique identifier of the plugin providing the artwork.
/// The display name of the artwork provider.
-/// Whether the artwork provider is enabled for the media library.
-/// The rank of the artwork provider, determining the order in which providers are tried.
+/// Whether the artwork provider is enabled for the media library. Always for a provider available for a library type, since a new provider starts disabled.
+/// The rank of the artwork provider, determining the order in which providers are tried. For a provider available for a library type, it is the rank a new library starts with, in alphabetical order of the plugin names.
public sealed record LibraryArtworkProviderResponse(
Guid PluginId,
string Name,
diff --git a/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs b/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs
index bb095299..8c2141d7 100644
--- a/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs
+++ b/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs
@@ -7,12 +7,12 @@ using System.Diagnostics;
namespace Lumina.Contracts.Responses.Plugins;
///
-/// Represents a book reader configured for a media library.
+/// Represents a book reader, either as configured for a media library, or as available for a library type, the way a new library of that type starts.
///
/// The unique identifier of the plugin providing the book reader.
/// The display name of the book reader.
/// The file extensions supported by the book reader.
-/// Whether the book reader is enabled for the media library.
+/// Whether the book reader is enabled for the media library. Always for a reader available for a library type, since a new reader starts disabled.
[DebuggerDisplay("Name: {Name}")]
public sealed record LibraryBookReaderResponse(
Guid PluginId,
diff --git a/src/Lumina.Contracts/Responses/Plugins/LibraryMetadataProviderResponse.cs b/src/Lumina.Contracts/Responses/Plugins/LibraryMetadataProviderResponse.cs
index b47a3b1a..923a5d54 100644
--- a/src/Lumina.Contracts/Responses/Plugins/LibraryMetadataProviderResponse.cs
+++ b/src/Lumina.Contracts/Responses/Plugins/LibraryMetadataProviderResponse.cs
@@ -5,12 +5,12 @@ using System;
namespace Lumina.Contracts.Responses.Plugins;
///
-/// Represents a metadata provider configured for a media library.
+/// Represents a metadata provider, either as configured for a media library, or as available for a library type, the way a new library of that type starts.
///
/// The unique identifier of the plugin providing the metadata.
/// The display name of the metadata provider.
-/// Whether the metadata provider is enabled for the media library.
-/// The rank of the metadata provider, determining the order in which providers are tried.
+/// Whether the metadata provider is enabled for the media library. Always for a provider available for a library type, since a new provider starts disabled.
+/// The rank of the metadata provider, determining the order in which providers are tried. For a provider available for a library type, it is the rank a new library starts with, in alphabetical order of the plugin names.
public sealed record LibraryMetadataProviderResponse(
Guid PluginId,
string Name,
diff --git a/src/Lumina.DataAccess/Common/Configuration/LibraryArtworkProviderConfigurationConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/LibraryArtworkProviderConfigurationConfiguration.cs
index 89618882..ada861a6 100644
--- a/src/Lumina.DataAccess/Common/Configuration/LibraryArtworkProviderConfigurationConfiguration.cs
+++ b/src/Lumina.DataAccess/Common/Configuration/LibraryArtworkProviderConfigurationConfiguration.cs
@@ -20,7 +20,7 @@ public class LibraryArtworkProviderConfigurationConfiguration : IEntityTypeConfi
builder.ToTable("LibraryArtworkProviderConfigurations");
builder.HasKey(configuration => configuration.Id);
builder.Property(configuration => configuration.Id)
- .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
+ .ValueGeneratedNever() // Because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it.
.HasColumnOrder(0);
builder.Property(configuration => configuration.LibraryId)
.IsRequired()
@@ -35,7 +35,7 @@ public class LibraryArtworkProviderConfigurationConfiguration : IEntityTypeConfi
.IsRequired()
.HasColumnOrder(4);
- // audit
+ // Audit.
builder.Property(configuration => configuration.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(5);
@@ -52,6 +52,9 @@ public class LibraryArtworkProviderConfigurationConfiguration : IEntityTypeConfi
.HasDefaultValue(null)
.HasColumnOrder(8);
- builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId });
+ // A media library has at most one artwork provider configuration per plugin, so the pair is unique; the repository upserts on it, and
+ // the constraint guarantees that two concurrent upserts cannot insert duplicate rows.
+ builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId })
+ .IsUnique();
}
}
diff --git a/src/Lumina.DataAccess/Common/Configuration/LibraryMetadataProviderConfigurationConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/LibraryMetadataProviderConfigurationConfiguration.cs
index 2130ed43..8b167ebb 100644
--- a/src/Lumina.DataAccess/Common/Configuration/LibraryMetadataProviderConfigurationConfiguration.cs
+++ b/src/Lumina.DataAccess/Common/Configuration/LibraryMetadataProviderConfigurationConfiguration.cs
@@ -20,7 +20,7 @@ public class LibraryMetadataProviderConfigurationConfiguration : IEntityTypeConf
builder.ToTable("LibraryMetadataProviderConfigurations");
builder.HasKey(configuration => configuration.Id);
builder.Property(configuration => configuration.Id)
- .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
+ .ValueGeneratedNever() // Because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it.
.HasColumnOrder(0);
builder.Property(configuration => configuration.LibraryId)
.IsRequired()
@@ -35,7 +35,7 @@ public class LibraryMetadataProviderConfigurationConfiguration : IEntityTypeConf
.IsRequired()
.HasColumnOrder(4);
- // audit
+ // Audit.
builder.Property(configuration => configuration.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(5);
@@ -52,6 +52,9 @@ public class LibraryMetadataProviderConfigurationConfiguration : IEntityTypeConf
.HasDefaultValue(null)
.HasColumnOrder(8);
- builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId });
+ // A media library has at most one metadata provider configuration per plugin, so the pair is unique; the repository upserts on it, and
+ // the constraint guarantees that two concurrent upserts cannot insert duplicate rows.
+ builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId })
+ .IsUnique();
}
}
diff --git a/src/Lumina.DataAccess/Common/Migrations/20261104063504_MakesProviderConfigurationsUniquePerLibraryAndPlugin.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20261104063504_MakesProviderConfigurationsUniquePerLibraryAndPlugin.Designer.cs
new file mode 100644
index 00000000..4dce5d66
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20261104063504_MakesProviderConfigurationsUniquePerLibraryAndPlugin.Designer.cs
@@ -0,0 +1,3904 @@
+//
+using System;
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ [DbContext(typeof(LuminaDbContext))]
+ [Migration("20261104063504_MakesProviderConfigurationsUniquePerLibraryAndPlugin")]
+ partial class MakesProviderConfigurationsUniquePerLibraryAndPlugin
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "10.0.11");
+
+ modelBuilder.Entity("AlbumGenres", b =>
+ {
+ b.Property("AlbumId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("AlbumId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("AlbumGenres", (string)null);
+ });
+
+ modelBuilder.Entity("AlbumTags", b =>
+ {
+ b.Property("AlbumId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("AlbumId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("AlbumTags", (string)null);
+ });
+
+ modelBuilder.Entity("ArtistGenres", b =>
+ {
+ b.Property("ArtistId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("ArtistId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("ArtistGenres", (string)null);
+ });
+
+ modelBuilder.Entity("ArtistTags", b =>
+ {
+ b.Property("ArtistId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("ArtistId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("ArtistTags", (string)null);
+ });
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("BookGenres", (string)null);
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("BookTags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("PermissionName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Permissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("RoleName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Roles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
+ {
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("RoleId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("RoleId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("RolePermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("UserId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("UserPermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId");
+
+ b.HasIndex("RoleId");
+
+ b.HasIndex("UserId", "RoleId")
+ .IsUnique();
+
+ b.ToTable("UserRoles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Genres", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Tags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Favorites.FavoriteEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("MediaItemId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("MediaKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "CreatedOnUtc");
+
+ b.HasIndex("UserId", "MediaKind", "CreatedOnUtc");
+
+ b.HasIndex("UserId", "MediaKind", "MediaItemId")
+ .IsUnique();
+
+ b.ToTable("Favorites", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaConsumption.MediaConsumptionRecordEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ConsecutivePagesRead")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(0)
+ .HasColumnOrder(14);
+
+ b.Property("ConsumedDurationMilliseconds")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(9);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(17);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("EndedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("LastActivityOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("LastPositionKind")
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("LastPositionLocation")
+ .HasMaxLength(4096)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("LastPositionTimeOffsetMilliseconds")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(11);
+
+ b.Property("LastProgressFraction")
+ .HasColumnType("REAL")
+ .HasColumnOrder(13);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("MediaItemId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("MediaKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("StartedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Version")
+ .IsConcurrencyToken()
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(15);
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "MediaKind", "StartedOnUtc");
+
+ b.HasIndex("UserId", "MediaKind", "MediaItemId", "LastActivityOnUtc");
+
+ b.ToTable("MediaConsumptionRecords", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaConsumption.MediaResumePointEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("LastConsumedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("LastPositionKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("LastPositionLocation")
+ .HasMaxLength(4096)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("LastPositionTimeOffsetMilliseconds")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(6);
+
+ b.Property("LastProgressFraction")
+ .HasColumnType("REAL")
+ .HasColumnOrder(8);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("MediaItemId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("MediaKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Version")
+ .IsConcurrencyToken()
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(10);
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "MediaKind", "MediaItemId")
+ .IsUnique();
+
+ b.ToTable("MediaResumePoints", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.MediaContributorEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Biography")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("DateOfBirth")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("DateOfDeath")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("DisplayName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1)
+ .UseCollation("NOCASE");
+
+ b.Property("LegalName")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.HasKey("Id");
+
+ b.HasIndex("DisplayName")
+ .IsUnique();
+
+ b.ToTable("MediaContributors", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("AlbumId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("MediaContributorId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("Role")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property