diff --git a/src/Lumina.Application/Common/DataAccess/Entities/Themes/ThemeEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/Themes/ThemeEntity.cs
new file mode 100644
index 00000000..4b698c47
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Entities/Themes/ThemeEntity.cs
@@ -0,0 +1,90 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Common;
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Entities.Themes;
+
+///
+/// Repository entity for a theme.
+///
+[DebuggerDisplay("ThemeId: {ThemeId}, Name: {Name}")]
+public class ThemeEntity : IStorageEntity, IAuditableEntity
+{
+ ///
+ /// Gets the Id of the theme.
+ ///
+ public required Guid Id { get; init; }
+
+ ///
+ /// Gets or sets the unique identifier of the theme, taken from its manifest and used by clients to reference it.
+ ///
+ public required string ThemeId { get; set; }
+
+ ///
+ /// Gets or sets the display name of the theme.
+ ///
+ public required string Name { get; set; }
+
+ ///
+ /// Gets or sets the description of the theme.
+ ///
+ public required string Description { get; set; }
+
+ ///
+ /// Gets or sets the author of the theme.
+ ///
+ public required string Author { get; set; }
+
+ ///
+ /// Gets or sets the version of the theme, using semantic version form.
+ ///
+ public required string Version { get; set; }
+
+ ///
+ /// Gets or sets the path of the theme preview image, relative to the theme pack root, or when the theme has no preview.
+ ///
+ public string? PreviewPath { get; set; }
+
+ ///
+ /// Gets or sets the source the theme was installed from.
+ ///
+ public required ThemeInstallSource InstallSource { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether this is the currently active theme. At most one theme can be current.
+ ///
+ public bool? IsCurrent { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether the theme was soft deleted, so it is not shown and not reinstalled automatically.
+ ///
+ public bool IsDeleted { get; set; }
+
+ ///
+ /// Gets or sets the UTC timestamp at which the theme was installed.
+ ///
+ public required DateTime InstalledAtUtc { get; set; }
+
+ ///
+ /// Gets or sets the time and date when the entity was added.
+ ///
+ public required DateTime CreatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the Id of the user that created the entity.
+ ///
+ public required Guid CreatedBy { get; set; }
+
+ ///
+ /// Gets or sets the optional time and date when the entity was updated.
+ ///
+ public DateTime? UpdatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the optional Id of the user that updated the entity.
+ ///
+ public required Guid? UpdatedBy { get; set; }
+}
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Themes/IThemeRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Themes/IThemeRepository.cs
new file mode 100644
index 00000000..db094c7a
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Themes/IThemeRepository.cs
@@ -0,0 +1,34 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.Common.Primitives;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Themes;
+
+///
+/// Interface for the repository for themes.
+///
+public interface IThemeRepository : IRepository,
+ IGetAllRepositoryAction,
+ IInsertRepositoryAction,
+ IUpdateRepositoryAction
+{
+ ///
+ /// Gets a theme identified by its manifest from the storage medium.
+ ///
+ /// The manifest id of the theme to get.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either a identified by , or an error.
+ Task> GetByThemeIdAsync(string themeId, CancellationToken cancellationToken);
+
+ ///
+ /// Gets the currently active theme from the storage medium.
+ ///
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the active , or an error.
+ Task> GetCurrentAsync(CancellationToken cancellationToken);
+}
diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
index f8717656..dc49b1f4 100644
--- a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
+++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
+using Lumina.Application.Common.DataAccess.Repositories.Themes;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using System.Threading;
using System.Threading.Tasks;
@@ -75,6 +76,11 @@ public interface IUnitOfWork
///
IPluginRepository PluginRepository { get; }
+ ///
+ /// Gets the theme repository.
+ ///
+ IThemeRepository ThemeRepository { get; }
+
///
/// Gets the user repository.
///
diff --git a/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeArchiveDto.cs b/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeArchiveDto.cs
new file mode 100644
index 00000000..58b3d228
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeArchiveDto.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
+
+///
+/// Data transfer object for a downloadable archive of a theme pack.
+///
+/// The bytes of the ZIP archive.
+/// The file name to expose when downloading the archive.
+/// The MIME content type of the archive.
+[DebuggerDisplay("FileName: {FileName}")]
+public sealed record ThemeArchiveDto(
+ byte[] Bytes,
+ string FileName,
+ string ContentType
+);
diff --git a/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeAssetDto.cs b/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeAssetDto.cs
new file mode 100644
index 00000000..307392cf
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeAssetDto.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
+
+///
+/// Data transfer object for a theme asset file served by the theme service.
+///
+/// The bytes of the asset file.
+/// The MIME content type of the asset file.
+[DebuggerDisplay("ContentType: {ContentType}")]
+public sealed record ThemeAssetDto(
+ byte[] Bytes,
+ string ContentType
+);
diff --git a/src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeManifestDto.cs b/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeManifestDto.cs
similarity index 87%
rename from src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeManifestDto.cs
rename to src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeManifestDto.cs
index 1e2f2b48..1888eda3 100644
--- a/src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeManifestDto.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Models/DTO/Themes/ThemeManifestDto.cs
@@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Diagnostics;
#endregion
-namespace Lumina.Presentation.Web.Common.DTO.Themes;
+namespace Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
///
-/// Data transfer object for the theme.json manifest of a theme package.
+/// Data transfer object for the theme.json manifest of a theme pack.
///
[DebuggerDisplay("Id: {Id}, Name: {Name}")]
public sealed class ThemeManifestDto
@@ -18,7 +18,7 @@ public sealed class ThemeManifestDto
public int SchemaVersion { get; set; }
///
- /// Gets or sets the unique identifier of the theme, a lowercase kebab-case value.
+ /// Gets or sets the unique identifier of the theme, a lowercase kebab-case value used by clients to reference it.
///
public string Id { get; set; } = string.Empty;
@@ -43,12 +43,12 @@ public sealed class ThemeManifestDto
public string Version { get; set; } = string.Empty;
///
- /// Gets or sets the preview image path relative to the theme package root, or when the theme has no preview.
+ /// Gets or sets the preview image path relative to the theme pack root, or when the theme has no preview.
///
public string? Preview { get; set; }
///
- /// Gets or sets the template mappings from template key to an HTML file path under templates/.
+ /// Gets or sets the template mappings from template key to a file path under templates/.
///
public Dictionary Templates { get; set; } = new(StringComparer.OrdinalIgnoreCase);
}
diff --git a/src/Lumina.Application/Common/Infrastructure/Themes/IThemeService.cs b/src/Lumina.Application/Common/Infrastructure/Themes/IThemeService.cs
new file mode 100644
index 00000000..f9e00778
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Themes/IThemeService.cs
@@ -0,0 +1,103 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
+using Lumina.Domain.Common.Primitives;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Themes;
+
+///
+/// Service for the storage and serving of theme packs.
+///
+public interface IThemeService
+{
+ ///
+ /// Gets a value indicating whether theme templates may contain script elements and theme assets may include script files.
+ ///
+ bool AllowThemeScripts { get; }
+
+ ///
+ /// Gets the maximum allowed size of a theme archive, in bytes.
+ ///
+ long MaxArchiveBytes { get; }
+
+ ///
+ /// Gets the identifier of the theme selected when no valid current theme is available.
+ ///
+ string DefaultThemeId { get; }
+
+ ///
+ /// Installs a theme pack from the provided archive, replacing the files of an existing theme with the same manifest id.
+ ///
+ /// The ZIP archive stream of the theme pack.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the parsed manifest of the installed theme, or an error.
+ Task> InstallAsync(Stream archive, CancellationToken cancellationToken);
+
+ ///
+ /// Reads the manifest of a theme pack archive without installing it.
+ ///
+ /// The path of the theme pack ZIP archive.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the parsed manifest, or an error.
+ Task> ReadManifestFromArchiveAsync(string archivePath, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes the stored files of a theme pack.
+ ///
+ /// The manifest id of the theme.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> DeleteAsync(string themeId, CancellationToken cancellationToken);
+
+ ///
+ /// Loads the manifest of an installed theme pack from its storage location.
+ ///
+ /// The manifest id of the theme.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the parsed manifest, or an error.
+ Task> LoadManifestAsync(string themeId, CancellationToken cancellationToken);
+
+ ///
+ /// Gets the sanitized content of the template selected by a page key, falling back to the default template when the key is missing.
+ ///
+ /// The manifest id of the theme.
+ /// The page key that selects the template.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the template content, or an error.
+ Task> GetTemplateAsync(string themeId, string pageKey, CancellationToken cancellationToken);
+
+ ///
+ /// Gets a theme asset file.
+ ///
+ /// The manifest id of the theme.
+ /// The asset path relative to the theme pack root.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the asset, or an error.
+ Task> GetAssetAsync(string themeId, string assetPath, CancellationToken cancellationToken);
+
+ ///
+ /// Builds a downloadable ZIP archive of an installed theme pack.
+ ///
+ /// The manifest id of the theme.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the archive, or an error.
+ Task> BuildArchiveAsync(string themeId, CancellationToken cancellationToken);
+
+ ///
+ /// Restores the files of a bundled theme from its shipped archive, used when the stored files were removed externally.
+ ///
+ /// The manifest id of the theme.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> RestoreBundledThemeAsync(string themeId, CancellationToken cancellationToken);
+
+ ///
+ /// Gets the paths of the theme pack archives shipped with the application.
+ ///
+ /// The list of bundled theme archive paths.
+ IReadOnlyList GetBundledThemeArchivePaths();
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/DeleteThemeRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/DeleteThemeRequestMapping.cs
new file mode 100644
index 00000000..144c8493
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/DeleteThemeRequestMapping.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
+using Lumina.Contracts.Requests.Themes;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class DeleteThemeRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted command.
+ public static DeleteThemeCommand ToCommand(this DeleteThemeRequest request)
+ {
+ return new DeleteThemeCommand(request.ThemeId);
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/GetThemeArchiveRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/GetThemeArchiveRequestMapping.cs
new file mode 100644
index 00000000..11a4b707
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/GetThemeArchiveRequestMapping.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
+using Lumina.Contracts.Requests.Themes;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class GetThemeArchiveRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetThemeArchiveQuery ToQuery(this GetThemeArchiveRequest request)
+ {
+ return new GetThemeArchiveQuery(request.ThemeId);
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/GetThemeAssetRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/GetThemeAssetRequestMapping.cs
new file mode 100644
index 00000000..c2f718d3
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/GetThemeAssetRequestMapping.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
+using Lumina.Contracts.Requests.Themes;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class GetThemeAssetRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetThemeAssetQuery ToQuery(this GetThemeAssetRequest request)
+ {
+ return new GetThemeAssetQuery(request.ThemeId, request.AssetPath);
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/GetThemeTemplateRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/GetThemeTemplateRequestMapping.cs
new file mode 100644
index 00000000..647c8db8
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/GetThemeTemplateRequestMapping.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
+using Lumina.Contracts.Requests.Themes;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class GetThemeTemplateRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetThemeTemplateQuery ToQuery(this GetThemeTemplateRequest request)
+ {
+ return new GetThemeTemplateQuery(request.ThemeId, request.PageKey);
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/InstallThemeRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/InstallThemeRequestMapping.cs
new file mode 100644
index 00000000..9e17d55b
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/InstallThemeRequestMapping.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
+using Lumina.Contracts.Requests.Themes;
+using System.IO;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class InstallThemeRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The ZIP archive stream of the theme pack.
+ /// The file name of the uploaded archive.
+ /// The converted command.
+ public static InstallThemeCommand ToCommand(this InstallThemeRequest request, Stream? archive, string? fileName)
+ {
+ return new InstallThemeCommand(archive, fileName);
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/SetCurrentThemeRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/SetCurrentThemeRequestMapping.cs
new file mode 100644
index 00000000..035b69e1
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/SetCurrentThemeRequestMapping.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
+using Lumina.Contracts.Requests.Themes;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class SetCurrentThemeRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted command.
+ public static SetCurrentThemeCommand ToCommand(this SetCurrentThemeRequest request)
+ {
+ return new SetCurrentThemeCommand(request.ThemeId);
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Themes/ThemeEntityMapping.cs b/src/Lumina.Application/Common/Mapping/Themes/ThemeEntityMapping.cs
new file mode 100644
index 00000000..c6818b85
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Themes/ThemeEntityMapping.cs
@@ -0,0 +1,32 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Contracts.Responses.Themes;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Themes;
+
+///
+/// Extension methods for converting .
+///
+public static class ThemeEntityMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The repository entity to be converted.
+ /// The converted response.
+ public static ThemeResponse ToResponse(this ThemeEntity theme)
+ {
+ return new ThemeResponse(
+ theme.Id,
+ theme.ThemeId,
+ theme.Name,
+ theme.Description,
+ theme.Author,
+ theme.Version,
+ theme.PreviewPath,
+ theme.InstallSource,
+ theme.IsCurrent,
+ theme.InstalledAtUtc);
+ }
+}
diff --git a/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs b/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs
index 86912552..2e14e2f2 100644
--- a/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs
+++ b/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs
@@ -39,6 +39,33 @@ public static class ValidatorUtilities
return ruleBuilder.Must(value => !value.HasValue || value.Value > valueToCompare);
}
+ ///
+ /// Defines a validation rule that ensures the long property is greater than the specified value.
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThan(this IRuleBuilder ruleBuilder, long valueToCompare)
+ {
+ return ruleBuilder.Must(value => value > valueToCompare);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the nullable long property is greater than the specified value.
+ ///
+ ///
+ /// If the property is , this rule passes (use to check for missing values).
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThan(this IRuleBuilder ruleBuilder, long valueToCompare)
+ {
+ return ruleBuilder.Must(value => !value.HasValue || value.Value > valueToCompare);
+ }
+
///
/// Defines a validation rule that ensures the decimal property is greater than the specified value.
///
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommand.cs b/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommand.cs
new file mode 100644
index 00000000..38666b55
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommand.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
+
+///
+/// Command for deleting a theme.
+///
+/// The manifest id of the theme to delete.
+[DebuggerDisplay("ThemeId: {ThemeId}")]
+public record DeleteThemeCommand(
+ string? ThemeId
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandHandler.cs b/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandHandler.cs
new file mode 100644
index 00000000..e329555e
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandHandler.cs
@@ -0,0 +1,129 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Themes;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
+
+///
+/// Handler for the command to delete a theme.
+///
+public class DeleteThemeCommandHandler : ICommandHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IThemeService _themeService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for the server-side storage and serving of theme packs.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for authorization related functionality.
+ /// Injected validator for application validation rules.
+ public DeleteThemeCommandHandler(
+ IUnitOfWork unitOfWork,
+ IThemeService themeService,
+ ICurrentUserService currentUserService,
+ IAuthorizationService authorizationService,
+ IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _themeService = themeService;
+ _currentUserService = currentUserService;
+ _authorizationService = authorizationService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the command to delete a theme.
+ ///
+ /// The command 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(DeleteThemeCommand command, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // only admins can delete themes
+ if (!await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false))
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getThemeResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(command.ThemeId!, cancellationToken).ConfigureAwait(false);
+ if (getThemeResult.IsFailure)
+ return getThemeResult.Errors;
+
+ ThemeEntity? theme = getThemeResult.Value;
+ if (theme is null || theme.IsDeleted)
+ return DomainErrors.Themes.ThemeNotFound;
+
+ Result> getAllResult = await _unitOfWork.ThemeRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
+ if (getAllResult.IsFailure)
+ return getAllResult.Errors;
+
+ List availableThemes = getAllResult.Value.Where(availableTheme => !availableTheme.IsDeleted).ToList();
+
+ // at least one bundled theme must always remain available, so the application never ends up without any theme
+ if (theme.InstallSource == ThemeInstallSource.Bundled)
+ {
+ int availableBundledThemes = availableThemes.Count(availableTheme => availableTheme.InstallSource == ThemeInstallSource.Bundled);
+ if (availableBundledThemes <= 1)
+ return DomainErrors.Themes.LastBundledThemeCannotBeDeleted;
+ }
+
+ // if the deleted theme was the active one, switch to another available theme, preferring the configured default
+ if (theme.IsCurrent == true)
+ {
+ ThemeEntity? replacementTheme = availableThemes
+ .Where(availableTheme => availableTheme.Id != theme.Id)
+ .OrderBy(availableTheme => string.Equals(availableTheme.ThemeId, _themeService.DefaultThemeId, StringComparison.OrdinalIgnoreCase) ? 0 : 1)
+ .ThenBy(availableTheme => availableTheme.ThemeId, StringComparer.OrdinalIgnoreCase)
+ .FirstOrDefault();
+ if (replacementTheme is null)
+ return DomainErrors.Themes.ThemeCannotBeDeleted;
+
+ replacementTheme.IsCurrent = true;
+ await _unitOfWork.ThemeRepository.UpdateAsync(replacementTheme, cancellationToken).ConfigureAwait(false);
+ }
+
+ theme.IsDeleted = true;
+ theme.IsCurrent = null;
+ theme.UpdatedOnUtc = DateTime.UtcNow;
+ theme.UpdatedBy = userId;
+ await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
+
+ await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
+
+ Result deleteFilesResult = await _themeService.DeleteAsync(theme.ThemeId, cancellationToken).ConfigureAwait(false);
+ if (deleteFilesResult.IsFailure)
+ return deleteFilesResult.Errors;
+
+ return Result.Success;
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandValidator.cs b/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandValidator.cs
new file mode 100644
index 00000000..752eb358
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandValidator.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
+
+///
+/// Validates the needed validation rules for .
+///
+public class DeleteThemeCommandValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public DeleteThemeCommandValidator()
+ {
+ RuleFor(command => command.ThemeId)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.ThemeIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommand.cs b/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommand.cs
new file mode 100644
index 00000000..488d3442
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommand.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+using System.IO;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
+
+///
+/// Command for installing a theme pack, replacing the files of an existing theme with the same manifest id.
+///
+/// The ZIP archive stream of the theme pack.
+/// The file name of the uploaded archive.
+[DebuggerDisplay("FileName: {FileName}")]
+public record InstallThemeCommand(
+ Stream? Archive,
+ string? FileName
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandHandler.cs b/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandHandler.cs
new file mode 100644
index 00000000..c804d7d1
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandHandler.cs
@@ -0,0 +1,148 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.Repositories.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
+using Lumina.Application.Common.Infrastructure.Themes;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Mapping.Themes;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
+
+///
+/// Handler for the command to install a theme pack.
+///
+public class InstallThemeCommandHandler : ICommandHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IThemeService _themeService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for the server-side storage and serving of theme packs.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for authorization related functionality.
+ /// Injected validator for application validation rules.
+ public InstallThemeCommandHandler(
+ IUnitOfWork unitOfWork,
+ IThemeService themeService,
+ ICurrentUserService currentUserService,
+ IAuthorizationService authorizationService,
+ IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _themeService = themeService;
+ _currentUserService = currentUserService;
+ _authorizationService = authorizationService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the command to install a theme pack.
+ ///
+ /// The command to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either a successfully installed , or an error.
+ ///
+ public async Task> HandleAsync(InstallThemeCommand command, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // only admins can install themes
+ if (!await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false))
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ // store the theme pack files on the server, replacing the files of an existing theme with the same manifest id
+ Result installResult = await _themeService.InstallAsync(command.Archive!, cancellationToken).ConfigureAwait(false);
+ if (installResult.IsFailure)
+ return installResult.Errors;
+
+ ThemeManifestDto manifest = installResult.Value;
+ Result getThemeResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(manifest.Id, cancellationToken).ConfigureAwait(false);
+ if (getThemeResult.IsFailure)
+ return getThemeResult.Errors;
+
+ ThemeEntity themeEntity;
+ if (getThemeResult.Value is not null)
+ {
+ ThemeEntity existingTheme = getThemeResult.Value;
+ themeEntity = new ThemeEntity
+ {
+ Id = existingTheme.Id,
+ ThemeId = manifest.Id,
+ Name = manifest.Name,
+ Description = manifest.Description,
+ Author = manifest.Author,
+ Version = manifest.Version,
+ PreviewPath = manifest.Preview,
+ InstallSource = existingTheme.InstallSource,
+ IsCurrent = existingTheme.IsCurrent,
+ IsDeleted = existingTheme.IsDeleted,
+ InstalledAtUtc = DateTime.UtcNow,
+ CreatedOnUtc = existingTheme.CreatedOnUtc,
+ CreatedBy = existingTheme.CreatedBy,
+ UpdatedOnUtc = DateTime.UtcNow,
+ UpdatedBy = userId
+ };
+
+ Result updateResult = await _unitOfWork.ThemeRepository.UpdateAsync(themeEntity, cancellationToken).ConfigureAwait(false);
+ if (updateResult.IsFailure)
+ return updateResult.Errors;
+ }
+ else
+ {
+ themeEntity = new ThemeEntity
+ {
+ Id = Guid.NewGuid(),
+ ThemeId = manifest.Id,
+ Name = manifest.Name,
+ Description = manifest.Description,
+ Author = manifest.Author,
+ Version = manifest.Version,
+ PreviewPath = manifest.Preview,
+ InstallSource = ThemeInstallSource.Uploaded,
+ InstalledAtUtc = DateTime.UtcNow,
+ CreatedOnUtc = DateTime.UtcNow,
+ CreatedBy = userId,
+ UpdatedBy = userId
+ };
+
+ Result insertResult = await _unitOfWork.ThemeRepository.InsertAsync(themeEntity, cancellationToken).ConfigureAwait(false);
+ if (insertResult.IsFailure)
+ {
+ // roll back the stored files so a failed install leaves no orphaned theme pack behind
+ await _themeService.DeleteAsync(manifest.Id, cancellationToken).ConfigureAwait(false);
+ return insertResult.Errors;
+ }
+ }
+
+ await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
+ return themeEntity.ToResponse();
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandValidator.cs b/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandValidator.cs
new file mode 100644
index 00000000..11c9698a
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandValidator.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Errors;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
+
+///
+/// Validates the needed validation rules for .
+///
+public class InstallThemeCommandValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InstallThemeCommandValidator()
+ {
+ RuleFor(command => command.Archive)
+ .NotNull()
+ .WithError(DomainErrors.Themes.ThemeArchiveCannotBeNull);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommand.cs b/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommand.cs
new file mode 100644
index 00000000..37bc72be
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommand.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
+
+///
+/// Command for setting the currently active theme.
+///
+/// The manifest id of the theme to activate.
+[DebuggerDisplay("ThemeId: {ThemeId}")]
+public record SetCurrentThemeCommand(
+ string? ThemeId
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandHandler.cs b/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandHandler.cs
new file mode 100644
index 00000000..3269b174
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandHandler.cs
@@ -0,0 +1,103 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Mapping.Themes;
+using Lumina.Contracts.Responses.Themes;
+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;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
+
+///
+/// Handler for the command to set the currently active theme.
+///
+public class SetCurrentThemeCommandHandler : ICommandHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for authorization related functionality.
+ /// Injected validator for application validation rules.
+ public SetCurrentThemeCommandHandler(
+ IUnitOfWork unitOfWork,
+ ICurrentUserService currentUserService,
+ IAuthorizationService authorizationService,
+ IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _currentUserService = currentUserService;
+ _authorizationService = authorizationService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the command to set the currently active theme.
+ ///
+ /// The command to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the newly active , or an error.
+ ///
+ public async Task> HandleAsync(SetCurrentThemeCommand command, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // only admins can change the active theme
+ if (!await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false))
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getThemeResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(command.ThemeId!, cancellationToken).ConfigureAwait(false);
+ if (getThemeResult.IsFailure)
+ return getThemeResult.Errors;
+
+ ThemeEntity? theme = getThemeResult.Value;
+ if (theme is null || theme.IsDeleted)
+ return DomainErrors.Themes.ThemeNotFound;
+
+ if (theme.IsCurrent == true)
+ return theme.ToResponse();
+
+ Result getCurrentResult = await _unitOfWork.ThemeRepository.GetCurrentAsync(cancellationToken).ConfigureAwait(false);
+ if (getCurrentResult.IsFailure)
+ return getCurrentResult.Errors;
+
+ ThemeEntity? currentTheme = getCurrentResult.Value;
+ if (currentTheme is not null && currentTheme.Id != theme.Id)
+ {
+ currentTheme.IsCurrent = null;
+ await _unitOfWork.ThemeRepository.UpdateAsync(currentTheme, cancellationToken).ConfigureAwait(false);
+ }
+
+ theme.IsCurrent = true;
+ theme.UpdatedOnUtc = DateTime.UtcNow;
+ theme.UpdatedBy = userId;
+ await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
+
+ await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
+ return theme.ToResponse();
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandValidator.cs b/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandValidator.cs
new file mode 100644
index 00000000..29ab5055
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandValidator.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
+
+///
+/// Validates the needed validation rules for .
+///
+public class SetCurrentThemeCommandValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SetCurrentThemeCommandValidator()
+ {
+ RuleFor(command => command.ThemeId)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.ThemeIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQuery.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQuery.cs
new file mode 100644
index 00000000..510ccf83
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQuery.cs
@@ -0,0 +1,13 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetCurrentTheme;
+
+///
+/// Query for retrieving the currently active theme.
+///
+[DebuggerDisplay("GetCurrentThemeQuery")]
+public record GetCurrentThemeQuery : IQuery;
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQueryHandler.cs
new file mode 100644
index 00000000..3014a68e
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQueryHandler.cs
@@ -0,0 +1,50 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Mapping.Themes;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using System.Threading;
+using System.Threading.Tasks;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetCurrentTheme;
+
+///
+/// Handler for the query to get the currently active theme.
+///
+public class GetCurrentThemeQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ public GetCurrentThemeQueryHandler(IUnitOfWork unitOfWork)
+ {
+ _unitOfWork = unitOfWork;
+ }
+
+ ///
+ /// Handles the query to get the currently active theme.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the active , or an error.
+ ///
+ public async Task> HandleAsync(GetCurrentThemeQuery query, CancellationToken cancellationToken)
+ {
+ Result getCurrentResult = await _unitOfWork.ThemeRepository.GetCurrentAsync(cancellationToken).ConfigureAwait(false);
+ if (getCurrentResult.IsFailure)
+ return getCurrentResult.Errors;
+
+ if (getCurrentResult.Value is null)
+ return DomainErrors.Themes.ThemeNotFound;
+
+ return getCurrentResult.Value.ToResponse();
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQuery.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQuery.cs
new file mode 100644
index 00000000..c5163a09
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQuery.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
+
+///
+/// Query for retrieving the downloadable archive of a theme.
+///
+/// The manifest id of the theme.
+[DebuggerDisplay("ThemeId: {ThemeId}")]
+public record GetThemeArchiveQuery(
+ string? ThemeId
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryHandler.cs
new file mode 100644
index 00000000..5d9012bb
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryHandler.cs
@@ -0,0 +1,68 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
+using Lumina.Application.Common.Infrastructure.Themes;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
+
+///
+/// Handler for the query to get the downloadable archive of a theme.
+///
+public class GetThemeArchiveQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IThemeService _themeService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for the server-side storage and serving of theme packs.
+ /// Injected validator for application validation rules.
+ public GetThemeArchiveQueryHandler(IUnitOfWork unitOfWork, IThemeService themeService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _themeService = themeService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the downloadable archive of a theme.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the archive of the theme, or an error.
+ ///
+ public async Task> HandleAsync(GetThemeArchiveQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Result getThemeResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(query.ThemeId!, cancellationToken).ConfigureAwait(false);
+ if (getThemeResult.IsFailure)
+ return getThemeResult.Errors;
+
+ ThemeEntity? theme = getThemeResult.Value;
+ if (theme is null || theme.IsDeleted)
+ return DomainErrors.Themes.ThemeNotFound;
+
+ Result archiveResult = await _themeService.BuildArchiveAsync(theme.ThemeId, cancellationToken).ConfigureAwait(false);
+ if (archiveResult.IsFailure)
+ return archiveResult.Errors;
+
+ return new ThemeArchiveResponse(archiveResult.Value.Bytes, archiveResult.Value.FileName, archiveResult.Value.ContentType);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryValidator.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryValidator.cs
new file mode 100644
index 00000000..073e83ac
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryValidator.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetThemeArchiveQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetThemeArchiveQueryValidator()
+ {
+ RuleFor(query => query.ThemeId)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.ThemeIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQuery.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQuery.cs
new file mode 100644
index 00000000..a576fafa
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQuery.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
+
+///
+/// Query for retrieving an asset file of a theme.
+///
+/// The manifest id of the theme.
+/// The asset path relative to the theme pack root.
+[DebuggerDisplay("ThemeId: {ThemeId}, AssetPath: {AssetPath}")]
+public record GetThemeAssetQuery(
+ string? ThemeId,
+ string? AssetPath
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryHandler.cs
new file mode 100644
index 00000000..9f69ce6a
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryHandler.cs
@@ -0,0 +1,82 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
+using Lumina.Application.Common.Infrastructure.Themes;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
+
+///
+/// Handler for the query to get an asset file of a theme.
+///
+public class GetThemeAssetQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IThemeService _themeService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for the server-side storage and serving of theme packs.
+ /// Injected validator for application validation rules.
+ public GetThemeAssetQueryHandler(IUnitOfWork unitOfWork, IThemeService themeService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _themeService = themeService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get an asset file of a theme.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the asset of the theme, or an error.
+ ///
+ public async Task> HandleAsync(GetThemeAssetQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Result getThemeResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(query.ThemeId!, cancellationToken).ConfigureAwait(false);
+ if (getThemeResult.IsFailure)
+ return getThemeResult.Errors;
+
+ ThemeEntity? theme = getThemeResult.Value;
+ if (theme is null || theme.IsDeleted)
+ return DomainErrors.Themes.ThemeNotFound;
+
+ Result assetResult = await _themeService.GetAssetAsync(theme.ThemeId, query.AssetPath!, cancellationToken).ConfigureAwait(false);
+ if (assetResult.IsFailure)
+ {
+ // the stored files of a bundled theme removed externally are restored, so its assets keep being served
+ if (theme.InstallSource == ThemeInstallSource.Bundled)
+ {
+ Result restoreResult = await _themeService.RestoreBundledThemeAsync(theme.ThemeId, cancellationToken).ConfigureAwait(false);
+ if (restoreResult.IsFailure)
+ return restoreResult.Errors;
+
+ assetResult = await _themeService.GetAssetAsync(theme.ThemeId, query.AssetPath!, cancellationToken).ConfigureAwait(false);
+ }
+
+ if (assetResult.IsFailure)
+ return assetResult.Errors;
+ }
+
+ return new ThemeAssetResponse(assetResult.Value.Bytes, assetResult.Value.ContentType);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryValidator.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryValidator.cs
new file mode 100644
index 00000000..2600048d
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryValidator.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetThemeAssetQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetThemeAssetQueryValidator()
+ {
+ RuleFor(query => query.ThemeId)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.ThemeIdCannotBeEmpty);
+
+ RuleFor(query => query.AssetPath)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.ThemeAssetPathCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQuery.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQuery.cs
new file mode 100644
index 00000000..f56b71ae
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQuery.cs
@@ -0,0 +1,13 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeSettings;
+
+///
+/// Query for retrieving the theme engine settings.
+///
+[DebuggerDisplay("GetThemeSettingsQuery")]
+public record GetThemeSettingsQuery : IQuery;
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQueryHandler.cs
new file mode 100644
index 00000000..595c53b5
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQueryHandler.cs
@@ -0,0 +1,41 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Themes;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeSettings;
+
+///
+/// Handler for the query to get the theme engine settings.
+///
+public class GetThemeSettingsQueryHandler : IQueryHandler>
+{
+ private readonly IThemeService _themeService;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service for the server-side storage and serving of theme packs.
+ public GetThemeSettingsQueryHandler(IThemeService themeService)
+ {
+ _themeService = themeService;
+ }
+
+ ///
+ /// Handles the query to get the theme engine settings.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing the theme engine settings, or an error.
+ ///
+ public Task> HandleAsync(GetThemeSettingsQuery query, CancellationToken cancellationToken)
+ {
+ ThemeSettingsResponse response = new(_themeService.MaxArchiveBytes, _themeService.AllowThemeScripts, _themeService.DefaultThemeId);
+ return Task.FromResult(Result.From(response));
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQuery.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQuery.cs
new file mode 100644
index 00000000..fbab092e
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQuery.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
+
+///
+/// Query for retrieving the template of a theme selected by a page key.
+///
+/// The manifest id of the theme.
+/// The page key that selects the template.
+[DebuggerDisplay("ThemeId: {ThemeId}, PageKey: {PageKey}")]
+public record GetThemeTemplateQuery(
+ string? ThemeId,
+ string? PageKey
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryHandler.cs
new file mode 100644
index 00000000..e547d303
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryHandler.cs
@@ -0,0 +1,113 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Themes;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Mapping.Themes;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
+
+///
+/// Handler for the query to get the template of a theme.
+///
+public class GetThemeTemplateQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IThemeService _themeService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for the server-side storage and serving of theme packs.
+ /// Injected validator for application validation rules.
+ public GetThemeTemplateQueryHandler(IUnitOfWork unitOfWork, IThemeService themeService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _themeService = themeService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the template of a theme.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the template of the theme, or an error.
+ ///
+ public async Task> HandleAsync(GetThemeTemplateQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Result getThemeResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(query.ThemeId!, cancellationToken).ConfigureAwait(false);
+ if (getThemeResult.IsFailure)
+ return getThemeResult.Errors;
+
+ ThemeEntity? theme = getThemeResult.Value;
+ if (theme is null || theme.IsDeleted)
+ return DomainErrors.Themes.ThemeNotFound;
+
+ Result templateResult = await _themeService.GetTemplateAsync(theme.ThemeId, query.PageKey!, cancellationToken).ConfigureAwait(false);
+ if (templateResult.IsFailure)
+ {
+ // the stored files of a bundled theme removed externally are restored, and if the broken theme was the
+ // active one, the configured default theme is activated, so clients always have a renderable theme
+ if (theme.InstallSource == ThemeInstallSource.Bundled && await TryRestoreBundledThemeAsync(theme, cancellationToken).ConfigureAwait(false))
+ templateResult = await _themeService.GetTemplateAsync(theme.ThemeId, query.PageKey!, cancellationToken).ConfigureAwait(false);
+
+ if (templateResult.IsFailure)
+ return templateResult.Errors;
+ }
+
+ return new ThemeTemplateResponse(theme.ToResponse(), templateResult.Value);
+ }
+
+ ///
+ /// Restores the files of a bundled theme whose stored files were removed externally, and switches the active theme to the configured default when the broken theme was the active one.
+ ///
+ /// The bundled theme to restore.
+ /// Cancellation token that can be used to stop the execution.
+ /// when the theme was restored; otherwise.
+ private async Task TryRestoreBundledThemeAsync(ThemeEntity theme, CancellationToken cancellationToken)
+ {
+ Result restoreResult = await _themeService.RestoreBundledThemeAsync(theme.ThemeId, cancellationToken).ConfigureAwait(false);
+ if (restoreResult.IsFailure)
+ return false;
+
+ if (theme.IsCurrent == true)
+ {
+ Result getDefaultResult = await _unitOfWork.ThemeRepository.GetByThemeIdAsync(_themeService.DefaultThemeId, cancellationToken).ConfigureAwait(false);
+ if (getDefaultResult.IsFailure)
+ return true;
+
+ ThemeEntity? defaultTheme = getDefaultResult.Value;
+ if (defaultTheme is not null && !defaultTheme.IsDeleted && defaultTheme.Id != theme.Id)
+ {
+ theme.IsCurrent = null;
+ await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
+
+ defaultTheme.IsCurrent = true;
+ await _unitOfWork.ThemeRepository.UpdateAsync(defaultTheme, cancellationToken).ConfigureAwait(false);
+
+ await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryValidator.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryValidator.cs
new file mode 100644
index 00000000..1818dbe4
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryValidator.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetThemeTemplateQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetThemeTemplateQueryValidator()
+ {
+ RuleFor(query => query.ThemeId)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.ThemeIdCannotBeEmpty);
+
+ RuleFor(query => query.PageKey)
+ .NotEmpty()
+ .WithError(DomainErrors.Themes.PageKeyCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQuery.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQuery.cs
new file mode 100644
index 00000000..05dd246d
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQuery.cs
@@ -0,0 +1,13 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemes;
+
+///
+/// Query for retrieving all installed themes.
+///
+[DebuggerDisplay("GetThemesQuery")]
+public record GetThemesQuery : IQuery;
diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs
new file mode 100644
index 00000000..d3ceca64
--- /dev/null
+++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs
@@ -0,0 +1,54 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Mapping.Themes;
+using Lumina.Contracts.Responses.Themes;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Core.Themes.Management.Queries.GetThemes;
+
+///
+/// Handler for the query to get all installed themes.
+///
+public class GetThemesQueryHandler : IQueryHandler>>
+{
+ private readonly IUnitOfWork _unitOfWork;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ public GetThemesQueryHandler(IUnitOfWork unitOfWork)
+ {
+ _unitOfWork = unitOfWork;
+ }
+
+ ///
+ /// Handles the query to get all installed themes.
+ ///
+ /// 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(GetThemesQuery query, CancellationToken cancellationToken)
+ {
+ Result> getThemesResult = await _unitOfWork.ThemeRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
+ if (getThemesResult.IsFailure)
+ return getThemesResult.Errors;
+
+ return Result.From>([.. getThemesResult.Value
+ .Where(theme => !theme.IsDeleted)
+ .OrderByDescending(theme => theme.InstallSource == ThemeInstallSource.Bundled)
+ .ThenBy(theme => theme.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(theme => theme.ToResponse())]);
+ }
+}
diff --git a/src/Lumina.Contracts/Requests/Themes/DeleteThemeRequest.cs b/src/Lumina.Contracts/Requests/Themes/DeleteThemeRequest.cs
new file mode 100644
index 00000000..1b7de807
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Themes/DeleteThemeRequest.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Themes;
+
+///
+/// Represents a request to delete a theme.
+///
+/// The manifest id of the theme to delete. Required.
+[DebuggerDisplay("ThemeId: {ThemeId}")]
+public record DeleteThemeRequest(
+ string? ThemeId
+);
diff --git a/src/Lumina.Contracts/Requests/Themes/GetThemeArchiveRequest.cs b/src/Lumina.Contracts/Requests/Themes/GetThemeArchiveRequest.cs
new file mode 100644
index 00000000..0d356b69
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Themes/GetThemeArchiveRequest.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Themes;
+
+///
+/// Represents a request to download the archive of a theme.
+///
+/// The manifest id of the theme. Required.
+[DebuggerDisplay("ThemeId: {ThemeId}")]
+public record GetThemeArchiveRequest(
+ string? ThemeId
+);
diff --git a/src/Lumina.Contracts/Requests/Themes/GetThemeAssetRequest.cs b/src/Lumina.Contracts/Requests/Themes/GetThemeAssetRequest.cs
new file mode 100644
index 00000000..24c01a97
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Themes/GetThemeAssetRequest.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Themes;
+
+///
+/// Represents a request to get an asset file of a theme.
+///
+/// The manifest id of the theme. Required.
+/// The asset path relative to the theme pack root. Required.
+[DebuggerDisplay("ThemeId: {ThemeId}, AssetPath: {AssetPath}")]
+public record GetThemeAssetRequest(
+ string? ThemeId,
+ string? AssetPath
+);
diff --git a/src/Lumina.Contracts/Requests/Themes/GetThemeTemplateRequest.cs b/src/Lumina.Contracts/Requests/Themes/GetThemeTemplateRequest.cs
new file mode 100644
index 00000000..47e047a8
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Themes/GetThemeTemplateRequest.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Themes;
+
+///
+/// Represents a request to get the template of a theme selected by a page key.
+///
+/// The manifest id of the theme. Required.
+/// The page key that selects the template. Required.
+[DebuggerDisplay("ThemeId: {ThemeId}, PageKey: {PageKey}")]
+public record GetThemeTemplateRequest(
+ string? ThemeId,
+ string? PageKey
+);
diff --git a/src/Lumina.Contracts/Requests/Themes/InstallThemeRequest.cs b/src/Lumina.Contracts/Requests/Themes/InstallThemeRequest.cs
new file mode 100644
index 00000000..d000c42b
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Themes/InstallThemeRequest.cs
@@ -0,0 +1,12 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Themes;
+
+///
+/// Represents a request to install a theme pack, sent as a multipart form whose single file field contains the theme archive.
+///
+[DebuggerDisplay("InstallThemeRequest")]
+public record InstallThemeRequest;
diff --git a/src/Lumina.Contracts/Requests/Themes/SetCurrentThemeRequest.cs b/src/Lumina.Contracts/Requests/Themes/SetCurrentThemeRequest.cs
new file mode 100644
index 00000000..9e171853
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Themes/SetCurrentThemeRequest.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Themes;
+
+///
+/// Represents a request to set the currently active theme.
+///
+/// The manifest id of the theme to activate. Required.
+[DebuggerDisplay("ThemeId: {ThemeId}")]
+public record SetCurrentThemeRequest(
+ string? ThemeId
+);
diff --git a/src/Lumina.Contracts/Responses/Themes/ThemeArchiveResponse.cs b/src/Lumina.Contracts/Responses/Themes/ThemeArchiveResponse.cs
new file mode 100644
index 00000000..841c8bc8
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/Themes/ThemeArchiveResponse.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.Themes;
+
+///
+/// Represents a theme archive response.
+///
+/// The bytes of the ZIP archive.
+/// The file name to expose when downloading the archive.
+/// The MIME content type of the archive.
+[DebuggerDisplay("FileName: {FileName}")]
+public record ThemeArchiveResponse(
+ byte[] Bytes,
+ string FileName,
+ string ContentType
+);
diff --git a/src/Lumina.Contracts/Responses/Themes/ThemeAssetResponse.cs b/src/Lumina.Contracts/Responses/Themes/ThemeAssetResponse.cs
new file mode 100644
index 00000000..f7c3d7b5
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/Themes/ThemeAssetResponse.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.Themes;
+
+///
+/// Represents a theme asset response.
+///
+/// The bytes of the asset file.
+/// The MIME content type of the asset file.
+[DebuggerDisplay("ContentType: {ContentType}")]
+public record ThemeAssetResponse(
+ byte[] Bytes,
+ string ContentType
+);
diff --git a/src/Lumina.Contracts/Responses/Themes/ThemeResponse.cs b/src/Lumina.Contracts/Responses/Themes/ThemeResponse.cs
new file mode 100644
index 00000000..adda0c8c
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/Themes/ThemeResponse.cs
@@ -0,0 +1,34 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.Themes;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.Themes;
+
+///
+/// Represents a theme response.
+///
+/// The unique identifier of the theme.
+/// The manifest id of the theme, used by clients to reference it.
+/// The display name of the theme.
+/// The description of the theme.
+/// The author of the theme.
+/// The version of the theme, using semantic version form.
+/// The path of the theme preview image, relative to the theme pack root, or when the theme has no preview.
+/// The source the theme was installed from.
+/// Whether the theme is the currently active one.
+/// The UTC timestamp at which the theme was installed.
+[DebuggerDisplay("ThemeId: {ThemeId}, Name: {Name}")]
+public record ThemeResponse(
+ Guid Id,
+ string ThemeId,
+ string Name,
+ string Description,
+ string Author,
+ string Version,
+ string? PreviewPath,
+ ThemeInstallSource InstallSource,
+ bool? IsCurrent,
+ DateTime InstalledAtUtc
+);
diff --git a/src/Lumina.Contracts/Responses/Themes/ThemeSettingsResponse.cs b/src/Lumina.Contracts/Responses/Themes/ThemeSettingsResponse.cs
new file mode 100644
index 00000000..c21851cc
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/Themes/ThemeSettingsResponse.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.Themes;
+
+///
+/// Represents a theme settings response.
+///
+/// The maximum allowed size of a theme archive, in bytes.
+/// Whether theme templates may contain script elements and theme assets may include script files.
+/// The identifier of the theme selected when no valid current theme is available.
+[DebuggerDisplay("MaxArchiveBytes: {MaxArchiveBytes}")]
+public record ThemeSettingsResponse(
+ long MaxArchiveBytes,
+ bool AllowThemeScripts,
+ string DefaultThemeId
+);
diff --git a/src/Lumina.Contracts/Responses/Themes/ThemeTemplateResponse.cs b/src/Lumina.Contracts/Responses/Themes/ThemeTemplateResponse.cs
new file mode 100644
index 00000000..7e14fc5d
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/Themes/ThemeTemplateResponse.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.Themes;
+
+///
+/// Represents a theme template response.
+///
+/// The theme the template belongs to.
+/// The sanitized content of the template.
+[DebuggerDisplay("ThemeId: {Theme.ThemeId}")]
+public record ThemeTemplateResponse(
+ ThemeResponse Theme,
+ string Template
+);
diff --git a/src/Lumina.DataAccess/Common/Configuration/ThemeConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/ThemeConfiguration.cs
new file mode 100644
index 00000000..5f36830f
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Configuration/ThemeConfiguration.cs
@@ -0,0 +1,100 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Themes;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using System;
+#endregion
+
+namespace Lumina.DataAccess.Common.Configuration;
+
+///
+/// Configures the entity mapping for the entity.
+///
+public class ThemeConfiguration : IEntityTypeConfiguration
+{
+ ///
+ /// Configures the entity.
+ ///
+ /// The builder to be used to configure the entity.
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("Themes");
+ builder.HasKey(theme => theme.Id);
+ builder.Property(theme => theme.Id)
+ .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the install, we need to tell EF not to generate it
+ .HasColumnOrder(0);
+
+ // the manifest id is the business key used by the clients, so it must be unique
+ builder.HasIndex(theme => theme.ThemeId)
+ .IsUnique();
+
+ builder.Property(theme => theme.ThemeId)
+ .IsRequired()
+ .HasMaxLength(64)
+ .HasColumnOrder(1);
+
+ builder.Property(theme => theme.Name)
+ .IsRequired()
+ .HasMaxLength(80)
+ .HasColumnOrder(2);
+
+ builder.Property(theme => theme.Description)
+ .IsRequired()
+ .HasMaxLength(300)
+ .HasColumnOrder(3);
+
+ builder.Property(theme => theme.Author)
+ .IsRequired()
+ .HasMaxLength(80)
+ .HasColumnOrder(4);
+
+ builder.Property(theme => theme.Version)
+ .IsRequired()
+ .HasMaxLength(40)
+ .HasColumnOrder(5);
+
+ builder.Property(theme => theme.PreviewPath)
+ .HasMaxLength(240)
+ .HasDefaultValue(null)
+ .HasColumnOrder(6);
+
+ builder.Property(theme => theme.InstallSource)
+ .IsRequired()
+ .HasConversion()
+ .HasColumnOrder(7);
+
+ // at most one theme can be current: the filtered unique index guarantees it at the database level, since every row that is not current has a null value here, and nulls are allowed to repeat
+ builder.HasIndex(theme => theme.IsCurrent)
+ .IsUnique()
+ .HasFilter("IsCurrent = 1");
+
+ builder.Property(theme => theme.IsCurrent)
+ .HasDefaultValue(null)
+ .HasColumnOrder(8);
+
+ builder.Property(theme => theme.IsDeleted)
+ .HasDefaultValue(false)
+ .HasColumnOrder(9);
+
+ builder.Property(theme => theme.InstalledAtUtc)
+ .IsRequired()
+ .HasColumnOrder(10);
+
+ // audit
+ builder.Property(theme => theme.CreatedOnUtc)
+ .IsRequired()
+ .HasColumnOrder(11);
+
+ builder.Property(theme => theme.CreatedBy)
+ .IsRequired()
+ .HasColumnOrder(12);
+
+ builder.Property(theme => theme.UpdatedOnUtc)
+ .HasDefaultValue(null)
+ .HasColumnOrder(13);
+
+ builder.Property(theme => theme.UpdatedBy)
+ .HasDefaultValue(null)
+ .HasColumnOrder(14);
+ }
+}
diff --git a/src/Lumina.DataAccess/Common/Migrations/20260819181057_AddsThemesTable.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20260819181057_AddsThemesTable.Designer.cs
new file mode 100644
index 00000000..d63afd4c
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20260819181057_AddsThemesTable.Designer.cs
@@ -0,0 +1,1302 @@
+//
+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("20260819181057_AddsThemesTable")]
+ partial class AddsThemesTable
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "10.0.11");
+
+ 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.MediaLibrary.Management.DirectoryScanFingerprintEntity", b =>
+ {
+ b.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("LastWriteTimeUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.HasKey("LibraryId", "Path");
+
+ b.HasIndex("LibraryId");
+
+ b.ToTable("DirectoryScanFingerprints", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CoverImage")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("DownloadMetadataFromWeb")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(true)
+ .HasColumnOrder(6);
+
+ b.Property("IsEnabled")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(true)
+ .HasColumnOrder(4);
+
+ b.Property("IsLocked")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("LibraryType")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("ShouldSaveMetadataInMediaDirectories")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("ShouldSkipUnchangedDirectoriesDuringScan")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(8);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Libraries", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Status")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("LibraryId", "Status", "CreatedOnUtc")
+ .IsDescending(true, false, true);
+
+ b.ToTable("LibraryScans", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b =>
+ {
+ b.Property("LibraryScanId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasMaxLength(24)
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(2);
+
+ b.Property("FileSize")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("Ticks")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.HasKey("LibraryScanId", "Path");
+
+ b.HasIndex("Path");
+
+ b.HasIndex("ContentHash", "FileSize", "Path");
+
+ b.ToTable("LibraryScanResults", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b =>
+ {
+ b.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("FileSize")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Ticks")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.HasKey("LibraryId", "Path");
+
+ b.HasIndex("LibraryId");
+
+ b.ToTable("LibraryScanSnapshots", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b =>
+ {
+ b.Property("LibraryScanId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("IsNew")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("NeedsRehash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(6);
+
+ b.Property("PreviousContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("Size")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(2);
+
+ b.Property("Ticks")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.HasKey("LibraryScanId", "Path");
+
+ b.HasIndex("LibraryScanId", "NeedsRehash");
+
+ b.ToTable("LibraryScanStagingResults", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ASIN")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(21);
+
+ b.Property("AppleBooksId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(29);
+
+ b.Property("BarnesAndNobleId")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(28);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(33);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(32);
+
+ b.Property("Description")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("Edition")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("Format")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("GoodreadsId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(22);
+
+ b.Property("GoogleBooksId")
+ .HasMaxLength(12)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(27);
+
+ b.Property("LCCN")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(23);
+
+ b.Property("LanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("LanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("LanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("LastMetadataUpdateUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(39);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(36);
+
+ b.Property("LibraryThingId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(26);
+
+ b.Property("MetadataProvider")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(40);
+
+ b.Property("MetadataStatus")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(38);
+
+ b.Property("OCLCNumber")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(24);
+
+ b.Property("OpenLibraryId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(25);
+
+ b.Property("OriginalLanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("OriginalLanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("OriginalLanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(15);
+
+ b.Property("OriginalReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("OriginalReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("OriginalTitle")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("PageCount")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(17);
+
+ b.Property("Path")
+ .IsRequired()
+ .HasMaxLength(2048)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(37);
+
+ b.Property("Publisher")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("ReReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("ReReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("ReleaseCountry")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("ReleaseVersion")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(35);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(34);
+
+ b.Property("VolumeNumber")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(20);
+
+ b.HasKey("Id");
+
+ b.HasIndex("LibraryId", "MetadataStatus");
+
+ b.HasIndex("LibraryId", "Path");
+
+ b.ToTable("Books", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryMetadataProviderConfigurationEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("IsEnabled")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("PluginId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("Rank")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.HasKey("Id");
+
+ b.HasIndex("LibraryId", "PluginId");
+
+ b.ToTable("LibraryMetadataProviderConfigurations", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.PluginEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Author")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("Description")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("LoadError")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("LoadStatus")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("SettingsJson")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("Version")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("Id");
+
+ b.ToTable("Plugins", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Author")
+ .IsRequired()
+ .HasMaxLength(80)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("Description")
+ .IsRequired()
+ .HasMaxLength(300)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("InstallSource")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("InstalledAtUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("IsCurrent")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(8);
+
+ b.Property("IsDeleted")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(false)
+ .HasColumnOrder(9);
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(80)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("PreviewPath")
+ .HasMaxLength(240)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("ThemeId")
+ .IsRequired()
+ .HasMaxLength(64)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("Version")
+ .IsRequired()
+ .HasMaxLength(40)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.HasIndex("IsCurrent")
+ .IsUnique()
+ .HasFilter("IsCurrent = 1");
+
+ b.HasIndex("ThemeId")
+ .IsUnique();
+
+ b.ToTable("Themes", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property