[CHANGE] Reworked db with interceptors
This commit is contained in:
9
Manager.Data/Entities/Audit/AuditableAttribute.cs
Normal file
9
Manager.Data/Entities/Audit/AuditableAttribute.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Manager.Data.Entities.Audit;
|
||||
|
||||
/// <summary>
|
||||
/// Make all properties in the entity audible, if they are changed this will be stored as a history in the db.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class AuditableAttribute : Attribute
|
||||
{
|
||||
}
|
22
Manager.Data/Entities/Audit/EntityHistory.cs
Normal file
22
Manager.Data/Entities/Audit/EntityHistory.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Manager.Data.Entities.Audit;
|
||||
|
||||
public class EntityHistory
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public required string EntityName { get; set; }
|
||||
[MaxLength(200)]
|
||||
public required string EntityId { get; set; }
|
||||
[MaxLength(200)]
|
||||
public required string PropertyName { get; set; }
|
||||
[MaxLength(1000)]
|
||||
public string? OldValue { get; set; }
|
||||
[MaxLength(1000)]
|
||||
public string? NewValue { get; set; }
|
||||
public DateTime ModifiedUtc { get; set; } = DateTime.UtcNow;
|
||||
[MaxLength(200)]
|
||||
public string? ChangedBy { get; set; }
|
||||
public EntityState ChangeType { get; set; }
|
||||
}
|
9
Manager.Data/Entities/Audit/NoAuditAttribute.cs
Normal file
9
Manager.Data/Entities/Audit/NoAuditAttribute.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Manager.Data.Entities.Audit;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies to ignore the properties in the entity to not audit.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class NoAuditAttribute : Attribute
|
||||
{
|
||||
}
|
@@ -1,5 +1,8 @@
|
||||
using Manager.Data.Entities.Audit;
|
||||
|
||||
namespace Manager.Data.Entities;
|
||||
|
||||
[NoAudit]
|
||||
public abstract class DateTimeBase
|
||||
{
|
||||
public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow;
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Manager.Data.Entities.Audit;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
public class CaptionEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Manager.Data.Entities.Audit;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
public class ChannelEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Manager.Data.Entities.Audit;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
public class ClientAccountEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
|
@@ -1,9 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Manager.Data.Entities.Audit;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
public class HttpCookieEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public required string ClientId { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public required string Name { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
@@ -15,6 +19,4 @@ public class HttpCookieEntity : DateTimeBase
|
||||
public DateTimeOffset? ExpiresUtc { get; set; }
|
||||
public bool Secure { get; set; }
|
||||
public bool HttpOnly { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public required string ClientId { get; set; }
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Manager.Data.Entities.Audit;
|
||||
using Manager.Data.Entities.LibraryContext.Join;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
public class MediaEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
@@ -17,7 +19,6 @@ public class MediaEntity : DateTimeBase
|
||||
public List<MediaFormatEntity> Formats { get; set; } = [];
|
||||
public List<CaptionEntity> Captions { get; set; } = [];
|
||||
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
|
||||
|
||||
public MediaExternalState ExternalState { get; set; } = MediaExternalState.Online;
|
||||
public bool IsDownloaded { get; set; }
|
||||
public MediaState State { get; set; } = MediaState.Indexed;
|
||||
|
@@ -1,8 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Manager.Data.Entities.Audit;
|
||||
using Manager.Data.Entities.LibraryContext.Join;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
public class PlaylistEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
|
Reference in New Issue
Block a user