Adds the server-side theme repository and reworks the web theme engine onto it

This commit is contained in:
BinaryAlley committed 2026-08-19 22:50:07 -07:00
1 parent 85928f7c3c
commit bf8faba24d
136 files changed
+6942 -1197

No files matched your search

@@ -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;
/// <summary>
/// Configures the entity mapping for the <see cref="ThemeEntity"/> entity.
/// </summary>
public class ThemeConfiguration : IEntityTypeConfiguration<ThemeEntity>
{
/// <summary>
/// Configures the <see cref="ThemeEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<ThemeEntity> 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<string>()
.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);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,60 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Lumina.DataAccess.Common.Migrations
{
/// <inheritdoc />
public partial class AddsThemesTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Themes",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
ThemeId = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 80, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 300, nullable: false),
Author = table.Column<string>(type: "TEXT", maxLength: 80, nullable: false),
Version = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
PreviewPath = table.Column<string>(type: "TEXT", maxLength: 240, nullable: true),
InstallSource = table.Column<string>(type: "TEXT", nullable: false),
IsCurrent = table.Column<bool>(type: "INTEGER", nullable: true),
IsDeleted = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: false),
InstalledAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Themes", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Themes_IsCurrent",
table: "Themes",
column: "IsCurrent",
unique: true,
filter: "IsCurrent = 1");
migrationBuilder.CreateIndex(
name: "IX_Themes_ThemeId",
table: "Themes",
column: "ThemeId",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Themes");
}
}
}
@@ -15,7 +15,7 @@ namespace Lumina.DataAccess.Common.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
modelBuilder.HasAnnotation("ProductVersion", "10.0.11");
modelBuilder.Entity("BookGenres", b =>
{
@@ -809,6 +809,94 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("Plugins", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
.HasColumnOrder(0);
b.Property<string>("Author")
.IsRequired()
.HasMaxLength(80)
.HasColumnType("TEXT")
.HasColumnOrder(4);
b.Property<Guid>("CreatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(12);
b.Property<DateTime>("CreatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(11);
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(300)
.HasColumnType("TEXT")
.HasColumnOrder(3);
b.Property<string>("InstallSource")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(7);
b.Property<DateTime>("InstalledAtUtc")
.HasColumnType("TEXT")
.HasColumnOrder(10);
b.Property<bool?>("IsCurrent")
.HasColumnType("INTEGER")
.HasColumnOrder(8);
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(false)
.HasColumnOrder(9);
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(80)
.HasColumnType("TEXT")
.HasColumnOrder(2);
b.Property<string>("PreviewPath")
.HasMaxLength(240)
.HasColumnType("TEXT")
.HasColumnOrder(6);
b.Property<string>("ThemeId")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("TEXT")
.HasColumnOrder(1);
b.Property<Guid?>("UpdatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(14);
b.Property<DateTime?>("UpdatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(13);
b.Property<string>("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<Guid>("Id")
@@ -0,0 +1,97 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Themes;
using Lumina.Application.Common.DataAccess.Repositories.Themes;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Errors;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Themes;
/// <summary>
/// Repository for themes.
/// </summary>
internal sealed class ThemeRepository : IThemeRepository
{
private readonly LuminaDbContext _luminaDbContext;
/// <summary>
/// Initializes a new instance of the <see cref="ThemeRepository"/> class.
/// </summary>
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
public ThemeRepository(LuminaDbContext luminaDbContext)
{
_luminaDbContext = luminaDbContext;
}
/// <summary>
/// Adds a new theme.
/// </summary>
/// <param name="theme">The theme to add.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Created>> InsertAsync(ThemeEntity theme, CancellationToken cancellationToken)
{
bool themeExists = await _luminaDbContext.Themes.AnyAsync(repositoryTheme => repositoryTheme.Id == theme.Id, cancellationToken).ConfigureAwait(false);
if (themeExists)
return Errors.Themes.ThemeNotFound;
_luminaDbContext.Themes.Add(theme);
return Result.Created;
}
/// <summary>
/// Updates a theme.
/// </summary>
/// <param name="data">The theme to update.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Updated>> UpdateAsync(ThemeEntity data, CancellationToken cancellationToken)
{
ThemeEntity? foundTheme = await _luminaDbContext.Themes
.FirstOrDefaultAsync(theme => theme.Id == data.Id, cancellationToken).ConfigureAwait(false);
if (foundTheme is null)
return Errors.Themes.ThemeNotFound;
_luminaDbContext.Entry(foundTheme).CurrentValues.SetValues(data);
return Result.Updated;
}
/// <summary>
/// Gets all themes from the storage medium.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="ThemeEntity"/>, or an error.</returns>
public async Task<Result<IEnumerable<ThemeEntity>>> GetAllAsync(CancellationToken cancellationToken)
{
return await _luminaDbContext.Themes.ToListAsync(cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Gets a theme identified by its manifest <paramref name="themeId"/> from the storage medium.
/// </summary>
/// <param name="themeId">The manifest id of the theme to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="ThemeEntity"/> identified by <paramref name="themeId"/>, or an error.</returns>
public async Task<Result<ThemeEntity?>> GetByThemeIdAsync(string themeId, CancellationToken cancellationToken)
{
return await _luminaDbContext.Themes
.FirstOrDefaultAsync(theme => theme.ThemeId == themeId, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Gets the currently active theme from the storage medium.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the active <see cref="ThemeEntity"/>, or an error.</returns>
public async Task<Result<ThemeEntity?>> GetCurrentAsync(CancellationToken cancellationToken)
{
return await _luminaDbContext.Themes
.FirstOrDefaultAsync(theme => theme.IsCurrent == true, cancellationToken).ConfigureAwait(false);
}
}
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Entities.Themes;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Microsoft.EntityFrameworkCore;
#endregion
@@ -32,6 +33,7 @@ public class LuminaDbContext : DbContext
public virtual DbSet<RolePermissionEntity> RolePermissions { get; set; } = null!;
public virtual DbSet<PluginEntity> Plugins { get; set; } = null!;
public virtual DbSet<LibraryMetadataProviderConfigurationEntity> LibraryMetadataProviderConfigurations { get; set; } = null!;
public virtual DbSet<ThemeEntity> Themes { get; set; } = null!;
/// <summary>
/// Initializes a new instance of the <see cref="LuminaDbContext"/> class.
@@ -3,12 +3,14 @@ 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 Lumina.Application.Common.DataAccess.UoW;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.Repositories.Books;
using Lumina.DataAccess.Core.Repositories.Libraries;
using Lumina.DataAccess.Core.Repositories.Plugins;
using Lumina.DataAccess.Core.Repositories.Themes;
using Lumina.DataAccess.Core.Repositories.Users;
using Microsoft.EntityFrameworkCore.Storage;
using System;
@@ -38,6 +40,7 @@ public class UnitOfWork : IUnitOfWork, IDisposable
private ILibraryScanStagingResultsRepository? _libraryScanStagingResultsRepository;
private ILibraryMetadataProviderConfigurationRepository? _libraryMetadataProviderConfigurationRepository;
private IPluginRepository? _pluginRepository;
private IThemeRepository? _themeRepository;
private IUserRepository? _userRepository;
private IUserSettingsRepository? _userSettingsRepository;
@@ -185,6 +188,18 @@ public class UnitOfWork : IUnitOfWork, IDisposable
}
}
/// <summary>
/// Gets the theme repository.
/// </summary>
public IThemeRepository ThemeRepository
{
get
{
_themeRepository ??= new ThemeRepository(_luminaDbContext);
return _themeRepository;
}
}
/// <summary>
/// Gets the user repository.
/// </summary>