mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 09:01:10 +00:00
Centralizes audit column ownership in the auditing interceptor
Removes explicit audit assignments from mappings, handlers, repositories, seeding, and background jobs, leaving the auditing interceptor as the only writer of the audit columns for ordinary saves. Adds a one-time initialization save so setup can attribute the original admin account and seeded rows to the SYSTEM audit identity, while ordinary anonymous writes remain unattributed with Guid.Empty.
This commit is contained in:
1 parent
b56fabf5df
commit
7253f1507c
98 files changed
+731
-516
No files matched your search
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the fixed audit identities used by the persistence layer.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SYSTEM identity is only for the explicit one-time application initialization save. Ordinary anonymous creation and modification remain
|
||||
/// unattributed with <see cref="Guid.Empty"/>; the SYSTEM identity is never inferred from a missing authenticated user.
|
||||
/// </remarks>
|
||||
public static class AuditIdentities
|
||||
{
|
||||
/// <summary>
|
||||
/// The fixed identifier of the SYSTEM audit user, used for rows created during application initialization, before any user account exists.
|
||||
/// </summary>
|
||||
public static readonly Guid s_systemUserId = Guid.Parse("11111111-1111-1111-1111-111111111111");
|
||||
}
|
||||
@@ -40,12 +40,12 @@ public class FavoriteEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -55,5 +55,5 @@ public class FavoriteEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -99,12 +99,12 @@ public class MediaConsumptionRecordEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -114,5 +114,5 @@ public class MediaConsumptionRecordEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -73,12 +73,12 @@ public class MediaResumePointEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -88,5 +88,5 @@ public class MediaResumePointEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -46,12 +46,12 @@ public class MediaContributorEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -61,5 +61,5 @@ public class MediaContributorEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+2
-2
@@ -37,12 +37,12 @@ public class AlbumContributorEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
|
||||
+3
-3
@@ -245,12 +245,12 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -260,5 +260,5 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+2
-2
@@ -37,12 +37,12 @@ public class ArtistContributorEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
|
||||
+3
-3
@@ -164,12 +164,12 @@ public class ArtistEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -179,5 +179,5 @@ public class ArtistEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -72,12 +72,12 @@ public class MusicArtworkEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -87,5 +87,5 @@ public class MusicArtworkEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+2
-2
@@ -37,12 +37,12 @@ public class TrackContributorEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
|
||||
+3
-3
@@ -305,12 +305,12 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -320,5 +320,5 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -121,12 +121,12 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -136,5 +136,5 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -53,12 +53,12 @@ public class LibraryScanEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -68,5 +68,5 @@ public class LibraryScanEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -50,12 +50,12 @@ public class LibraryScanSnapshotEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -65,5 +65,5 @@ public class LibraryScanSnapshotEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -65,12 +65,12 @@ public class BookArtworkEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -80,5 +80,5 @@ public class BookArtworkEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+2
-2
@@ -37,12 +37,12 @@ public class BookContributorEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
|
||||
+3
-3
@@ -241,12 +241,12 @@ public class BookEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -256,5 +256,5 @@ public class BookEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -61,12 +61,12 @@ public class PlaylistEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -76,5 +76,5 @@ public class PlaylistEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -40,12 +40,12 @@ public class LibraryArtworkProviderConfigurationEntity : IStorageEntity, IAudita
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -55,5 +55,5 @@ public class LibraryArtworkProviderConfigurationEntity : IStorageEntity, IAudita
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -35,12 +35,12 @@ public class LibraryBookReaderConfigurationEntity : IStorageEntity, IAuditableEn
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -50,5 +50,5 @@ public class LibraryBookReaderConfigurationEntity : IStorageEntity, IAuditableEn
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -40,12 +40,12 @@ public class LibraryMetadataProviderConfigurationEntity : IStorageEntity, IAudit
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -55,5 +55,5 @@ public class LibraryMetadataProviderConfigurationEntity : IStorageEntity, IAudit
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -56,12 +56,12 @@ public class PluginEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -71,5 +71,5 @@ public class PluginEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -71,12 +71,12 @@ public class ScheduledJobEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -86,5 +86,5 @@ public class ScheduledJobEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -56,12 +56,12 @@ public class ScheduledJobExecutionEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -71,5 +71,5 @@ public class ScheduledJobExecutionEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+3
-3
@@ -41,12 +41,12 @@ public class SchedulerDisplayPreferencesEntity : IStorageEntity, IAuditableEntit
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -56,5 +56,5 @@ public class SchedulerDisplayPreferencesEntity : IStorageEntity, IAuditableEntit
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -71,12 +71,12 @@ public class ThemeEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
@@ -86,5 +86,5 @@ public class ThemeEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -15,26 +15,23 @@ public interface IDataSeedService
|
||||
/// <summary>
|
||||
/// Sets up default authorization permissions in the system.
|
||||
/// </summary>
|
||||
/// <param name="adminId">The unique identifier of the admin admin user who will own these permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken);
|
||||
Task<Result<Created>> SetDefaultAuthorizationPermissionsAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sets up default authorization roles in the system.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user for whom roles will be set.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken);
|
||||
Task<Result<Created>> SetDefaultAuthorizationRolesAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Assigns admin role permissions to the admin user.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user to receive admin role permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken);
|
||||
Task<Result<Created>> SetAdminRolePermissionsAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Assigns admin role to the admin user.
|
||||
|
||||
@@ -185,6 +185,14 @@ public interface IUnitOfWork
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the changes made during the one-time application initialization, whose audit values are provided explicitly by the bootstrap code instead of
|
||||
/// being stamped by the auditing interceptor.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> SaveChangesAsInitializationAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Detaches all the entities tracked by the unit of work, freeing the memory they occupy.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Favorites;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Favorites;
|
||||
@@ -23,11 +22,7 @@ public static class FavoriteMapping
|
||||
Id = domainEntity.Id.Value,
|
||||
UserId = domainEntity.UserId.Value,
|
||||
MediaKind = domainEntity.MediaKind,
|
||||
MediaItemId = domainEntity.MediaItemId.Value,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc.Value : null,
|
||||
UpdatedBy = null
|
||||
MediaItemId = domainEntity.MediaItemId.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
-6
@@ -44,12 +44,7 @@ public static class MediaConsumptionRecordMapping
|
||||
: null,
|
||||
LastProgressFraction = domainEntity.LastProgressFraction,
|
||||
ConsecutivePagesRead = domainEntity.ConsecutivePagesRead,
|
||||
Version = 1,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Version = 1
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -37,12 +37,7 @@ public static class MediaResumePointMapping
|
||||
: null,
|
||||
LastProgressFraction = domainEntity.LastProgressFraction,
|
||||
LastConsumedOnUtc = domainEntity.LastConsumedOnUtc,
|
||||
Version = 1,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Version = 1
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+2
-10
@@ -69,18 +69,10 @@ public static class AlbumMapping
|
||||
Id = Guid.CreateVersion7(),
|
||||
AlbumId = domainEntity.Id.Value,
|
||||
MediaContributorId = contributor.ContributorId.Value,
|
||||
Role = contributor.Role,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
Role = contributor.Role
|
||||
})],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
Tracks = [.. domainEntity.Tracks.Select(track => track.ToRepositoryEntity(domainEntity.Id.Value, libraryId))],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Tracks = [.. domainEntity.Tracks.Select(track => track.ToRepositoryEntity(domainEntity.Id.Value, libraryId))]
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -51,17 +51,9 @@ public static class ArtistMapping
|
||||
Id = Guid.CreateVersion7(),
|
||||
ArtistId = domainEntity.Id.Value,
|
||||
MediaContributorId = contributor.ContributorId.Value,
|
||||
Role = contributor.Role,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
Role = contributor.Role
|
||||
})],
|
||||
Albums = [.. domainEntity.Albums.Select(album => album.ToRepositoryEntity(domainEntity.Id.Value, domainEntity.LibraryId.Value))],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Albums = [.. domainEntity.Albums.Select(album => album.ToRepositoryEntity(domainEntity.Id.Value, domainEntity.LibraryId.Value))]
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -75,10 +75,7 @@ public static class TrackMapping
|
||||
Id = Guid.CreateVersion7(),
|
||||
TrackId = domainEntity.Id.Value,
|
||||
MediaContributorId = contributor.ContributorId.Value,
|
||||
Role = contributor.Role,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
Role = contributor.Role
|
||||
})],
|
||||
Moods = [.. domainEntity.Moods.ToRepositoryEntities()],
|
||||
Isrcs = [.. domainEntity.Isrcs.ToRepositoryEntities()],
|
||||
@@ -88,12 +85,7 @@ public static class TrackMapping
|
||||
WorkIswcs = domainEntity.Work.HasValue
|
||||
? [.. domainEntity.Work.Value.Iswcs.Select(iswc => new TrackWorkIswcEntity(iswc))]
|
||||
: [],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
@@ -51,16 +50,8 @@ public static class LibraryMapping
|
||||
UserId = domainEntity.UserId.Value, // Rest of properties will be populated by EF Core.
|
||||
Status = default,
|
||||
User = null!,
|
||||
Library = null!,
|
||||
CreatedBy = default,
|
||||
CreatedOnUtc = default,
|
||||
UpdatedBy = default,
|
||||
})],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Library = null!
|
||||
})]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
@@ -25,11 +24,7 @@ public static class LibraryScanMapping
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
Status = domainEntity.Status,
|
||||
User = null!,
|
||||
Library = null!,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc.Value : null,
|
||||
UpdatedBy = Guid.Empty
|
||||
Library = null!
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-12
@@ -63,17 +63,9 @@ public static class BookMapping
|
||||
Id = Guid.CreateVersion7(),
|
||||
BookId = domainEntity.Id.Value,
|
||||
MediaContributorId = contributor.ContributorId.Value,
|
||||
Role = contributor.Role,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
Role = contributor.Role
|
||||
})],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null,
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,7 +106,5 @@ public static class BookMapping
|
||||
entity.GoogleBooksId = domainEntity.GoogleBooksId.HasValue ? domainEntity.GoogleBooksId.Value : null;
|
||||
entity.BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null;
|
||||
entity.AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null;
|
||||
entity.UpdatedOnUtc = DateTime.UtcNow;
|
||||
entity.UpdatedBy = Guid.CreateVersion7();
|
||||
}
|
||||
}
|
||||
+2
-8
@@ -21,9 +21,8 @@ public static class UpdateBookCoverCommandMapping
|
||||
/// <param name="existingCover">The existing cover artwork of the book, or <see langword="null"/> when the book has none.</param>
|
||||
/// <param name="bookId">The Id of the book the cover belongs to.</param>
|
||||
/// <param name="storedCoverPath">The relative path of the stored cover image.</param>
|
||||
/// <param name="userId">The Id of the user that stored the cover image.</param>
|
||||
/// <returns>The cover artwork of the book, carrying the stored cover image.</returns>
|
||||
public static BookArtworkEntity ToRepositoryEntity(this UpdateBookCoverCommand command, BookArtworkEntity? existingCover, Guid bookId, string storedCoverPath, Guid userId)
|
||||
public static BookArtworkEntity ToRepositoryEntity(this UpdateBookCoverCommand command, BookArtworkEntity? existingCover, Guid bookId, string storedCoverPath)
|
||||
{
|
||||
if (existingCover is null)
|
||||
{
|
||||
@@ -34,18 +33,13 @@ public static class UpdateBookCoverCommandMapping
|
||||
ArtworkType = ArtworkType.Cover,
|
||||
Ordinal = 0,
|
||||
FileName = storedCoverPath,
|
||||
Status = ArtworkStatus.Enriched,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = userId,
|
||||
UpdatedBy = null
|
||||
Status = ArtworkStatus.Enriched
|
||||
};
|
||||
}
|
||||
|
||||
existingCover.FileName = storedCoverPath;
|
||||
existingCover.Status = ArtworkStatus.Enriched;
|
||||
existingCover.LastUpdateUtc = DateTime.UtcNow;
|
||||
existingCover.UpdatedOnUtc = DateTime.UtcNow;
|
||||
existingCover.UpdatedBy = userId;
|
||||
return existingCover;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
@@ -30,11 +29,7 @@ public static class PlaylistMapping
|
||||
.OrderBy(entry => entry.Position)
|
||||
.Select(entry => entry.ToRepositoryEntity(domainEntity.Id.Value))],
|
||||
// This is the correct count for an insert. The update path deliberately keeps the stored count, because details edits never load the entries and must not overwrite it.
|
||||
EntryCount = domainEntity.Entries.Count,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc.Value : null,
|
||||
UpdatedBy = null
|
||||
EntryCount = domainEntity.Entries.Count
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -99,11 +99,7 @@ public static class ScheduledJobEntityMapping
|
||||
Status = status,
|
||||
OwnerUserId = repositoryEntity.OwnerUserId,
|
||||
LastStartedOnUtc = lastStartedOnUtc,
|
||||
LastCompletedOnUtc = lastCompletedOnUtc,
|
||||
CreatedOnUtc = repositoryEntity.CreatedOnUtc,
|
||||
CreatedBy = repositoryEntity.CreatedBy,
|
||||
UpdatedOnUtc = repositoryEntity.UpdatedOnUtc,
|
||||
UpdatedBy = repositoryEntity.UpdatedBy
|
||||
LastCompletedOnUtc = lastCompletedOnUtc
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -44,11 +44,7 @@ public static class ScheduledJobExecutionEntityMapping
|
||||
IsCycleRun = repositoryEntity.IsCycleRun,
|
||||
WasCycleActive = repositoryEntity.WasCycleActive,
|
||||
StartedOnUtc = repositoryEntity.StartedOnUtc,
|
||||
CompletedOnUtc = completedOnUtc,
|
||||
CreatedOnUtc = repositoryEntity.CreatedOnUtc,
|
||||
CreatedBy = repositoryEntity.CreatedBy,
|
||||
UpdatedOnUtc = repositoryEntity.UpdatedOnUtc,
|
||||
UpdatedBy = repositoryEntity.UpdatedBy
|
||||
CompletedOnUtc = completedOnUtc
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Contracts.Responses.Scheduling;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Scheduling;
|
||||
@@ -32,11 +31,7 @@ public static class ScheduledJobMapping
|
||||
Status = domainEntity.Status,
|
||||
OwnerUserId = domainEntity.OwnerUserId.Value,
|
||||
LastStartedOnUtc = domainEntity.LastStartedOnUtc.HasValue ? domainEntity.LastStartedOnUtc.Value : null,
|
||||
LastCompletedOnUtc = domainEntity.LastCompletedOnUtc.HasValue ? domainEntity.LastCompletedOnUtc.Value : null,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc.Value : null,
|
||||
UpdatedBy = Guid.Empty
|
||||
LastCompletedOnUtc = domainEntity.LastCompletedOnUtc.HasValue ? domainEntity.LastCompletedOnUtc.Value : null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Seed;
|
||||
@@ -107,7 +108,7 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = id,
|
||||
CreatedBy = AuditIdentities.s_systemUserId,
|
||||
LibraryScans = [],
|
||||
};
|
||||
// If the user enabled two factor auth, include a QR with the totp secret.
|
||||
@@ -124,20 +125,20 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
|
||||
Result<Created> insertUserResult = await _unitOfWork.UserRepository.InsertAsync(user, cancellationToken).ConfigureAwait(false);
|
||||
if (insertUserResult.IsFailure)
|
||||
return insertUserResult.Errors;
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsInitializationAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
// Set the default permissions, roles, roles permissions.
|
||||
Result<Created> setPermissionsResult = await _dataSeedService.SetDefaultAuthorizationPermissionsAsync(id, cancellationToken).ConfigureAwait(false);
|
||||
Result<Created> setPermissionsResult = await _dataSeedService.SetDefaultAuthorizationPermissionsAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (setPermissionsResult.IsFailure)
|
||||
return setPermissionsResult.Errors;
|
||||
|
||||
Result<Created> setRoleResult = await _dataSeedService.SetDefaultAuthorizationRolesAsync(id, cancellationToken).ConfigureAwait(false);
|
||||
Result<Created> setRoleResult = await _dataSeedService.SetDefaultAuthorizationRolesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (setRoleResult.IsFailure)
|
||||
return setRoleResult.Errors;
|
||||
|
||||
Result<Created> setRolePermissionResult = await _dataSeedService.SetAdminRolePermissionsAsync(id, cancellationToken).ConfigureAwait(false);
|
||||
Result<Created> setRolePermissionResult = await _dataSeedService.SetAdminRolePermissionsAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (setRolePermissionResult.IsFailure)
|
||||
return setRolePermissionResult.Errors;
|
||||
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ public class UpdateBookCoverCommandHandler : ICommandHandler<UpdateBookCoverComm
|
||||
|
||||
// Map the newly stored cover image onto the artwork of the book, replacing the existing cover or adding a new one.
|
||||
BookArtworkEntity? existingCover = existingBook.Artwork.FirstOrDefault(artwork => artwork.ArtworkType == ArtworkType.Cover);
|
||||
BookArtworkEntity coverArtwork = command.ToRepositoryEntity(existingCover, bookId, storeArtworkResult.Value, userId);
|
||||
BookArtworkEntity coverArtwork = command.ToRepositoryEntity(existingCover, bookId, storeArtworkResult.Value);
|
||||
if (existingCover is null)
|
||||
existingBook.Artwork.Add(coverArtwork);
|
||||
|
||||
|
||||
+1
-5
@@ -71,11 +71,7 @@ public class UpdateSchedulerDisplayPreferencesCommandHandler : ICommandHandler<U
|
||||
UserId = userId,
|
||||
JobTypeFilter = command.JobTypeFilter,
|
||||
DisplayTimeSpan = command.DisplayTimeSpan,
|
||||
DisplayTimeUnit = command.DisplayTimeUnit,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
DisplayTimeUnit = command.DisplayTimeUnit
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.SchedulerDisplayPreferencesRepository.UpsertAsync(displayPreferences, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
|
||||
+1
-5
@@ -72,11 +72,7 @@ public class ScheduledJobExecutionStartedDomainEventHandler : IDomainEventHandle
|
||||
IsCycleRun = domainEvent.IsCycleRun,
|
||||
WasCycleActive = wasCycleActive,
|
||||
StartedOnUtc = domainEvent.StartedOnUtc,
|
||||
CompletedOnUtc = null,
|
||||
CreatedOnUtc = scheduledJob.CreatedOnUtc,
|
||||
CreatedBy = scheduledJob.CreatedBy,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
CompletedOnUtc = null
|
||||
};
|
||||
Result<Created> insertExecutionResult = await _unitOfWork.ScheduledJobExecutionRepository.InsertAsync(execution, cancellationToken).ConfigureAwait(false);
|
||||
if (insertExecutionResult.IsFailure)
|
||||
|
||||
-2
@@ -119,8 +119,6 @@ public class DeleteThemeCommandHandler : ICommandHandler<DeleteThemeCommand, Res
|
||||
// Bundled themes are soft deleted, so they can be restored automatically later, as long as the user did not delete them.
|
||||
theme.IsDeleted = true;
|
||||
theme.IsCurrent = null;
|
||||
theme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
theme.UpdatedBy = userId;
|
||||
await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
|
||||
+2
-9
@@ -103,11 +103,7 @@ public class InstallThemeCommandHandler : ICommandHandler<InstallThemeCommand, R
|
||||
IsCurrent = existingTheme.IsCurrent,
|
||||
// Reinstalling a theme must bring it back even if it was soft deleted before, so the uploaded pack becomes visible again.
|
||||
IsDeleted = false,
|
||||
InstalledAtUtc = DateTime.UtcNow,
|
||||
CreatedOnUtc = existingTheme.CreatedOnUtc,
|
||||
CreatedBy = existingTheme.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = userId
|
||||
InstalledAtUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
Result<Updated> updateResult = await _unitOfWork.ThemeRepository.UpdateAsync(themeEntity, cancellationToken).ConfigureAwait(false);
|
||||
@@ -126,10 +122,7 @@ public class InstallThemeCommandHandler : ICommandHandler<InstallThemeCommand, R
|
||||
Version = manifest.Version,
|
||||
PreviewPath = manifest.Preview,
|
||||
InstallSource = ThemeInstallSource.Uploaded,
|
||||
InstalledAtUtc = DateTime.UtcNow,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = userId,
|
||||
UpdatedBy = userId
|
||||
InstalledAtUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
Result<Created> insertResult = await _unitOfWork.ThemeRepository.InsertAsync(themeEntity, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
-2
@@ -93,8 +93,6 @@ public class RestoreThemeCommandHandler : ICommandHandler<RestoreThemeCommand, R
|
||||
|
||||
theme.IsDeleted = false;
|
||||
theme.IsCurrent = null;
|
||||
theme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
theme.UpdatedBy = userId;
|
||||
Result<Updated> updateResult = await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
|
||||
-2
@@ -96,8 +96,6 @@ public class SetCurrentThemeCommandHandler : ICommandHandler<SetCurrentThemeComm
|
||||
|
||||
// Activate the requested theme and persist its update.
|
||||
theme.IsCurrent = true;
|
||||
theme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
theme.UpdatedBy = userId;
|
||||
await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
-7
@@ -7,7 +7,6 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using System;
|
||||
@@ -28,7 +27,6 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, R
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
private readonly ITotpTokenGenerator _totpTokenGenerator;
|
||||
private readonly IQRCodeGenerator _qRCodeGenerator;
|
||||
private readonly IDateTimeProvider _dateTimeProvider;
|
||||
private readonly IValidator<RegisterUserCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,7 +37,6 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, R
|
||||
/// <param name="cryptographyService">Injected service for cryptographic functionality.</param>
|
||||
/// <param name="totpTokenGenerator">Injected service for generating and validating TOTP tokens.</param>
|
||||
/// <param name="qRCodeGenerator">Injected service for generating QR codes.</param>
|
||||
/// <param name="dateTimeProvider">Injected service for time related concerns.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public RegisterUserCommandHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
@@ -47,7 +44,6 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, R
|
||||
ICryptographyService cryptographyService,
|
||||
ITotpTokenGenerator totpTokenGenerator,
|
||||
IQRCodeGenerator qRCodeGenerator,
|
||||
IDateTimeProvider dateTimeProvider,
|
||||
IValidator<RegisterUserCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
@@ -55,7 +51,6 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, R
|
||||
_cryptographyService = cryptographyService;
|
||||
_totpTokenGenerator = totpTokenGenerator;
|
||||
_qRCodeGenerator = qRCodeGenerator;
|
||||
_dateTimeProvider = dateTimeProvider;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
@@ -88,11 +83,9 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, R
|
||||
Id = id,
|
||||
Username = command.Username!,
|
||||
Password = Uri.EscapeDataString(_hashService.HashString(command.Password!)),
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow,
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = id,
|
||||
LibraryScans = [],
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
@@ -64,6 +65,9 @@ public sealed class UpdateAuditableEntitiesInterceptor : SaveChangesInterceptor
|
||||
{
|
||||
if (context is null)
|
||||
return;
|
||||
// Initialization is the one save whose audit identity is provided explicitly, because no user account exists yet.
|
||||
if (context is LuminaDbContext luminaDbContext && luminaDbContext.IsInitializationSave)
|
||||
return;
|
||||
|
||||
Guid? userId = _currentUserService.UserId;
|
||||
DateTime utcNow = _dateTimeProvider.UtcNow;
|
||||
@@ -106,6 +110,6 @@ public sealed class UpdateAuditableEntitiesInterceptor : SaveChangesInterceptor
|
||||
|
||||
// Set modification properties.
|
||||
entry.Entity.UpdatedOnUtc = utcNow;
|
||||
entry.Entity.UpdatedBy = userId ?? Guid.Parse("11111111-1111-1111-1111-111111111111"); // "SYSTEM" user Id.
|
||||
entry.Entity.UpdatedBy = userId ?? default;
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -89,10 +89,7 @@ internal sealed class MediaContributorRepository : IMediaContributorRepository
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
DisplayName = displayName,
|
||||
LegalName = legalName,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
LegalName = legalName
|
||||
};
|
||||
_luminaDbContext.MediaContributors.Add(contributor);
|
||||
return contributor;
|
||||
|
||||
@@ -173,12 +173,7 @@ internal sealed class MusicArtworkRepository : IMusicArtworkRepository
|
||||
ArtworkType = ArtworkType.Cover,
|
||||
Ordinal = 0,
|
||||
FileName = fileName,
|
||||
Status = ArtworkStatus.Enriched,
|
||||
CreatedOnUtc = now,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
Status = ArtworkStatus.Enriched
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Seed;
|
||||
@@ -41,18 +42,17 @@ public class DataSeedService : IDataSeedService
|
||||
/// <summary>
|
||||
/// Sets up default authorization permissions in the system.
|
||||
/// </summary>
|
||||
/// <param name="adminId">The unique identifier of the admin admin user who will own these permissions.</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>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken)
|
||||
public async Task<Result<Created>> SetDefaultAuthorizationPermissionsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Create the default authorization permissions and add them to the repository.
|
||||
PermissionEntity[] defaultPermissions =
|
||||
[
|
||||
new() { PermissionName = AuthorizationPermission.CanViewUsers, CreatedBy = adminId, CreatedOnUtc = _dateTimeProvider.UtcNow },
|
||||
new() { PermissionName = AuthorizationPermission.CanDeleteUsers, CreatedBy = adminId, CreatedOnUtc = _dateTimeProvider.UtcNow },
|
||||
new() { PermissionName = AuthorizationPermission.CanRegisterUsers, CreatedBy = adminId, CreatedOnUtc = _dateTimeProvider.UtcNow },
|
||||
new() { PermissionName = AuthorizationPermission.CanCreateLibraries, CreatedBy = adminId, CreatedOnUtc = _dateTimeProvider.UtcNow }
|
||||
new() { PermissionName = AuthorizationPermission.CanViewUsers, CreatedOnUtc = _dateTimeProvider.UtcNow, CreatedBy = AuditIdentities.s_systemUserId },
|
||||
new() { PermissionName = AuthorizationPermission.CanDeleteUsers, CreatedOnUtc = _dateTimeProvider.UtcNow, CreatedBy = AuditIdentities.s_systemUserId },
|
||||
new() { PermissionName = AuthorizationPermission.CanRegisterUsers, CreatedOnUtc = _dateTimeProvider.UtcNow, CreatedBy = AuditIdentities.s_systemUserId },
|
||||
new() { PermissionName = AuthorizationPermission.CanCreateLibraries, CreatedOnUtc = _dateTimeProvider.UtcNow, CreatedBy = AuditIdentities.s_systemUserId }
|
||||
];
|
||||
foreach (PermissionEntity permission in defaultPermissions)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ public class DataSeedService : IDataSeedService
|
||||
if (insertPermissionResult.IsFailure)
|
||||
return insertPermissionResult.Errors;
|
||||
}
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsInitializationAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Created;
|
||||
@@ -69,15 +69,14 @@ public class DataSeedService : IDataSeedService
|
||||
/// <summary>
|
||||
/// Sets up default authorization roles in the system.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user for whom roles will be set.</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>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken)
|
||||
public async Task<Result<Created>> SetDefaultAuthorizationRolesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Create the default authorization roles and add them to the repository.
|
||||
RoleEntity[] defaultRoles =
|
||||
[
|
||||
new() { RoleName = AuthorizationRoles.ADMIN, CreatedBy = userId, CreatedOnUtc = _dateTimeProvider.UtcNow }
|
||||
new() { RoleName = AuthorizationRoles.ADMIN, CreatedOnUtc = _dateTimeProvider.UtcNow, CreatedBy = AuditIdentities.s_systemUserId }
|
||||
];
|
||||
foreach (RoleEntity role in defaultRoles)
|
||||
{
|
||||
@@ -85,7 +84,7 @@ public class DataSeedService : IDataSeedService
|
||||
if (insertRoleResult.IsFailure)
|
||||
return insertRoleResult.Errors;
|
||||
}
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsInitializationAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Created;
|
||||
@@ -94,10 +93,9 @@ public class DataSeedService : IDataSeedService
|
||||
/// <summary>
|
||||
/// Assigns admin role permissions to the admin user.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user to receive admin role permissions.</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>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken)
|
||||
public async Task<Result<Created>> SetAdminRolePermissionsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the admin role.
|
||||
Result<RoleEntity?> getAdminRoleResult = await _unitOfWork.RoleRepository.GetByNameAsync(AuthorizationRoles.ADMIN, cancellationToken).ConfigureAwait(false);
|
||||
@@ -121,14 +119,14 @@ public class DataSeedService : IDataSeedService
|
||||
PermissionId = permission.Id,
|
||||
Role = getAdminRoleResult.Value,
|
||||
RoleId = getAdminRoleResult.Value.Id,
|
||||
CreatedBy = userId,
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow,
|
||||
CreatedBy = AuditIdentities.s_systemUserId
|
||||
};
|
||||
Result<Created> insertRolePermissionResult = await _unitOfWork.RolePermissionRepository.InsertAsync(rolePermissionEntity, cancellationToken).ConfigureAwait(false);
|
||||
if (insertRolePermissionResult.IsFailure)
|
||||
return insertRolePermissionResult.Errors;
|
||||
}
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsInitializationAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Created;
|
||||
@@ -161,18 +159,18 @@ public class DataSeedService : IDataSeedService
|
||||
// Add the admin role to the admin user.
|
||||
UserRoleEntity userRole = new()
|
||||
{
|
||||
CreatedBy = userId,
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow,
|
||||
Role = getAdminRoleResult.Value,
|
||||
RoleId = getAdminRoleResult.Value.Id,
|
||||
User = getUserResult.Value,
|
||||
UserId = getUserResult.Value.Id
|
||||
UserId = getUserResult.Value.Id,
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow,
|
||||
CreatedBy = AuditIdentities.s_systemUserId
|
||||
};
|
||||
Result<Created> insertUserRoleResult = await _unitOfWork.UserRoleRepository.InsertAsync(userRole, cancellationToken).ConfigureAwait(false);
|
||||
if (insertUserRoleResult.IsFailure)
|
||||
return insertUserRoleResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsInitializationAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Created;
|
||||
@@ -208,7 +206,7 @@ public class DataSeedService : IDataSeedService
|
||||
if (insertScheduledJobResult.IsFailure)
|
||||
return insertScheduledJobResult.Errors;
|
||||
}
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsInitializationAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
return Result.Created;
|
||||
@@ -241,9 +239,7 @@ public class DataSeedService : IDataSeedService
|
||||
LastStartedOnUtc = null,
|
||||
LastCompletedOnUtc = null,
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow,
|
||||
CreatedBy = adminUserId,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
CreatedBy = AuditIdentities.s_systemUserId
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,12 @@ public class LuminaDbContext : DbContext
|
||||
/// </summary>
|
||||
public virtual DbSet<MediaResumePointEntity> MediaResumePoints { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the changes are being saved by the one-time application initialization, whose audit values are provided explicitly instead of
|
||||
/// being stamped by the auditing interceptor.
|
||||
/// </summary>
|
||||
internal bool IsInitializationSave { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LuminaDbContext"/> class.
|
||||
/// </summary>
|
||||
|
||||
@@ -467,6 +467,35 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Success>> SaveChangesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await SaveChangesCoreAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the changes made during the one-time application initialization, whose audit values are provided explicitly by the bootstrap code instead of
|
||||
/// being stamped by the auditing interceptor.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Success>> SaveChangesAsInitializationAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.IsInitializationSave = true;
|
||||
try
|
||||
{
|
||||
return await SaveChangesCoreAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_luminaDbContext.IsInitializationSave = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the changes made to the database, reporting expected persistence conflicts as failure results.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
private async Task<Result<Success>> SaveChangesCoreAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
+1
-4
@@ -647,10 +647,7 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
ContentHash = contentHash,
|
||||
Status = status,
|
||||
Provider = provider,
|
||||
LastUpdateUtc = DateTime.UtcNow,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
LastUpdateUtc = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+3
-12
@@ -261,10 +261,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
||||
LibraryId = libraryId,
|
||||
Name = name,
|
||||
MusicBrainzArtistId = musicBrainzArtistId,
|
||||
MetadataStatus = MetadataStatus.Pending,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
MetadataStatus = MetadataStatus.Pending
|
||||
};
|
||||
}
|
||||
|
||||
@@ -293,10 +290,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
||||
MusicBrainzReleaseArtistId = musicBrainzReleaseArtistId,
|
||||
ReleaseTypes = firstStagedItem.ReleaseType is null ? [] : [new AlbumReleaseTypeEntity(firstStagedItem.ReleaseType.Value)],
|
||||
OriginalReleaseYear = firstStagedItem.ReleaseYear,
|
||||
MetadataStatus = MetadataStatus.Pending,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
MetadataStatus = MetadataStatus.Pending
|
||||
};
|
||||
}
|
||||
|
||||
@@ -335,10 +329,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
||||
MusicBrainzTrackId = stagedItem.MusicBrainzTrackId,
|
||||
MusicBrainzWorkId = stagedItem.MusicBrainzWorkId,
|
||||
WorkTitle = stagedItem.WorkTitle,
|
||||
MetadataStatus = MetadataStatus.Pending,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
MetadataStatus = MetadataStatus.Pending
|
||||
};
|
||||
}
|
||||
}
|
||||
-2
@@ -146,8 +146,6 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med
|
||||
library.MetadataProvidersConfigurationFingerprint = metadataFingerprint;
|
||||
library.ArtworkProvidersConfigurationFingerprint = artworkFingerprint;
|
||||
library.PathTemplateFingerprint = pathTemplateFingerprint;
|
||||
library.UpdatedOnUtc = DateTime.UtcNow;
|
||||
library.UpdatedBy = Guid.CreateVersion7();
|
||||
|
||||
Result<Success> saveChangesResult = await unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
|
||||
+1
-12
@@ -209,8 +209,6 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
else
|
||||
{
|
||||
coverArtwork.Status = ArtworkStatus.Failed;
|
||||
coverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||
coverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -239,8 +237,6 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
else
|
||||
{
|
||||
existingCoverArtwork.Status = ArtworkStatus.Failed;
|
||||
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||
existingCoverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -261,8 +257,6 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
existingCoverArtwork.Status = ArtworkStatus.Enriched;
|
||||
existingCoverArtwork.Provider = resolvedArtwork.ProviderName;
|
||||
existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow;
|
||||
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||
existingCoverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -271,8 +265,6 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
existingCoverArtwork!.Status = ArtworkStatus.Enriched;
|
||||
existingCoverArtwork.Provider = resolvedArtwork.ProviderName;
|
||||
existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow;
|
||||
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||
existingCoverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,10 +332,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
ContentHash = contentHash,
|
||||
Status = status,
|
||||
Provider = provider,
|
||||
LastUpdateUtc = lastUpdateUtc,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
LastUpdateUtc = lastUpdateUtc
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -176,10 +176,7 @@ internal sealed class BooksMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
||||
Path = path,
|
||||
Title = title,
|
||||
VolumeNumber = volumeNumber,
|
||||
MetadataStatus = MetadataStatus.Pending,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
MetadataStatus = MetadataStatus.Pending
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -220,8 +220,6 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM
|
||||
{
|
||||
// No metadata provider returned usable metadata, so the book is marked as failed to enrich, keeping its previous metadata.
|
||||
bookEntity.MetadataStatus = MetadataStatus.Failed;
|
||||
bookEntity.UpdatedOnUtc = DateTime.UtcNow;
|
||||
bookEntity.UpdatedBy = Guid.CreateVersion7();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,10 +245,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM
|
||||
Id = Guid.CreateVersion7(),
|
||||
BookId = bookEntity.Id,
|
||||
MediaContributorId = contributorEntity.Id,
|
||||
Role = role,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
Role = role
|
||||
});
|
||||
domainContributors.Add(BookMediaContributor.Create(MediaContributorId.Create(contributorEntity.Id), role).Value);
|
||||
}
|
||||
|
||||
@@ -295,9 +295,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
LibraryId = libraryId,
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -337,9 +334,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
LibraryId = libraryId,
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -389,9 +383,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -442,9 +433,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -484,9 +472,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -526,9 +511,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
Rank = nextRank,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -583,9 +565,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
PluginId = pluginId,
|
||||
IsEnabled = isEnabled,
|
||||
Rank = index + 1,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
configuration.IsEnabled = isEnabled;
|
||||
configuration.Rank = index + 1;
|
||||
@@ -641,9 +620,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
PluginId = pluginId,
|
||||
IsEnabled = isEnabled,
|
||||
Rank = index + 1,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
configuration.IsEnabled = isEnabled;
|
||||
configuration.Rank = index + 1;
|
||||
@@ -697,9 +673,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
||||
LibraryId = libraryId,
|
||||
PluginId = pluginId,
|
||||
IsEnabled = isEnabled,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
configuration.IsEnabled = isEnabled;
|
||||
Result<Updated> upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -74,10 +74,7 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
||||
Author = plugin.Author,
|
||||
Version = plugin.Version.ToString(),
|
||||
Description = plugin.Description,
|
||||
LoadStatus = PluginLoadStatus.Loaded,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
LoadStatus = PluginLoadStatus.Loaded
|
||||
};
|
||||
Result<Updated> upsertResult = await unitOfWork.PluginRepository.UpsertAsync(pluginEntity, stoppingToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
@@ -98,10 +95,7 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
||||
Version = string.Empty,
|
||||
Description = string.Empty,
|
||||
LoadStatus = PluginLoadStatus.FailedToLoad,
|
||||
LoadError = loadError.ErrorMessage,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
LoadError = loadError.ErrorMessage
|
||||
};
|
||||
Result<Updated> upsertResult = await unitOfWork.PluginRepository.UpsertAsync(pluginEntity, stoppingToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
|
||||
@@ -191,11 +191,7 @@ public sealed class ScheduledJobSchedulerJob : BackgroundService, IScheduledJobS
|
||||
Status = ScheduledJobStatus.Active,
|
||||
OwnerUserId = ownerUserId,
|
||||
LastStartedOnUtc = null,
|
||||
LastCompletedOnUtc = null,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = ownerUserId,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
LastCompletedOnUtc = null
|
||||
};
|
||||
Result<Created> insertScheduledJobResult = await unitOfWork.ScheduledJobRepository.InsertAsync(technicalDataCleanupJob, cancellationToken).ConfigureAwait(false);
|
||||
if (insertScheduledJobResult.IsFailure)
|
||||
|
||||
@@ -84,8 +84,6 @@ internal static class ThemeSynchronizer
|
||||
if (!string.Equals(existingTheme.Version, manifestResult.Value.Version, StringComparison.Ordinal))
|
||||
{
|
||||
existingTheme.Version = manifestResult.Value.Version;
|
||||
existingTheme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
existingTheme.UpdatedBy = default;
|
||||
Result<Updated> updateResult = await unitOfWork.ThemeRepository.UpdateAsync(existingTheme, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
logger.LogWarning("Failed to update the version of theme '{ThemeId}': {Error}", existingTheme.ThemeId, updateResult.FirstError.Description);
|
||||
@@ -103,10 +101,7 @@ internal static class ThemeSynchronizer
|
||||
Version = manifestResult.Value.Version,
|
||||
PreviewPath = manifestResult.Value.Preview,
|
||||
InstallSource = ThemeInstallSource.Bundled,
|
||||
InstalledAtUtc = DateTime.UtcNow,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
InstalledAtUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
Result<Created> insertResult = await unitOfWork.ThemeRepository.InsertAsync(themeEntity, cancellationToken).ConfigureAwait(false);
|
||||
@@ -174,8 +169,6 @@ internal static class ThemeSynchronizer
|
||||
// A bundled theme whose files could not be recovered is soft deleted, so it is not shown anymore, but can be restored later.
|
||||
brokenTheme.IsDeleted = true;
|
||||
brokenTheme.IsCurrent = null;
|
||||
brokenTheme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
brokenTheme.UpdatedBy = default;
|
||||
Result<Updated> updateResult = await unitOfWork.ThemeRepository.UpdateAsync(brokenTheme, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
logger.LogWarning("Failed to delete theme '{ThemeId}': {Error}", brokenTheme.ThemeId, updateResult.FirstError.Description);
|
||||
@@ -227,8 +220,6 @@ internal static class ThemeSynchronizer
|
||||
return;
|
||||
|
||||
defaultTheme.IsCurrent = true;
|
||||
defaultTheme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
defaultTheme.UpdatedBy = default;
|
||||
Result<Updated> updateResult = await unitOfWork.ThemeRepository.UpdateAsync(defaultTheme, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
logger.LogWarning("Failed to activate theme '{ThemeId}': {Error}", defaultTheme.ThemeId, updateResult.FirstError.Description);
|
||||
|
||||
Reference in new issue
Block a user