[CHANGE] Fixed auditing, storing images from account import
This commit is contained in:
@@ -36,11 +36,11 @@ public class AuditInterceptor : SaveChangesInterceptor
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
var primaryKey = entry.Properties.First(p => p.Metadata.IsPrimaryKey()).CurrentValue?.ToString() ?? "Unknown";
|
||||
var primaryKey = entry.Properties.First(p => p.Metadata.IsPrimaryKey()).CurrentValue?.ToString();
|
||||
|
||||
var declaredProperties = entry.Entity.GetType()
|
||||
.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
|
||||
.Where(p => !Attribute.IsDefined(p.DeclaringType!, typeof(NoAuditAttribute)))
|
||||
.Where(p => !Attribute.IsDefined(p.DeclaringType!, typeof(NoAuditAttribute), false))
|
||||
.Select(p => p.Name)
|
||||
.ToHashSet();
|
||||
|
||||
@@ -78,6 +78,7 @@ public class AuditInterceptor : SaveChangesInterceptor
|
||||
{
|
||||
return new EntityAudit
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
EntityName = entry.Entity.GetType().Name,
|
||||
EntityId = primaryKey ?? "Unknown",
|
||||
PropertyName = prop.Metadata.Name,
|
||||
|
@@ -23,7 +23,7 @@ public sealed class LibraryDbContext : DbContext
|
||||
public DbSet<MediaEntity> Media { get; set; }
|
||||
public DbSet<MediaFormatEntity> MediaFormats { get; set; }
|
||||
public DbSet<PlaylistEntity> Playlists { get; set; }
|
||||
// Other media (images)?
|
||||
public DbSet<FileEntity> Files { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@@ -32,9 +32,10 @@ public sealed class LibraryDbContext : DbContext
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<EntityAudit>(eh =>
|
||||
modelBuilder.Entity<EntityAudit>(ea =>
|
||||
{
|
||||
eh.ToTable("audits");
|
||||
ea.HasKey(a => a.Id);
|
||||
ea.ToTable("audits");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<CaptionEntity>(ce =>
|
||||
@@ -96,6 +97,12 @@ public sealed class LibraryDbContext : DbContext
|
||||
ple.ToTable("playlists");
|
||||
ple.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<FileEntity>(file =>
|
||||
{
|
||||
file.ToTable("files");
|
||||
file.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
/* Join tables */
|
||||
|
||||
|
@@ -4,7 +4,8 @@ public static class DataConstants
|
||||
{
|
||||
public static class DbContext
|
||||
{
|
||||
public const int DefaultDbStringSize = 100;
|
||||
public const int DefaultDbDescriptionStringSize = 500;
|
||||
public const int DefaultDbStringSize = 500;
|
||||
public const int DefaultDbDescriptionStringSize = 5500;
|
||||
public const int DefaultDbUrlSize = 10000;
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ namespace Manager.Data.Entities.Audit;
|
||||
|
||||
public class EntityAudit
|
||||
{
|
||||
public required Guid Id { get; set; }
|
||||
[MaxLength(200)]
|
||||
public required string EntityName { get; set; }
|
||||
[MaxLength(200)]
|
||||
|
@@ -5,6 +5,6 @@ namespace Manager.Data.Entities;
|
||||
[NoAudit]
|
||||
public abstract class DateTimeBase
|
||||
{
|
||||
public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow;
|
||||
public DateTime LastModifiedUtc { get; set; } = DateTime.UtcNow;
|
||||
public DateTime CreatedAtUtc { get; set; }
|
||||
public DateTime LastModifiedUtc { get; set; }
|
||||
}
|
25
Manager.Data/Entities/LibraryContext/FileEntity.cs
Normal file
25
Manager.Data/Entities/LibraryContext/FileEntity.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
public class FileEntity : DateTimeBase
|
||||
{
|
||||
public required Guid Id { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public required string ForeignKey { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public required string FileType { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public required string RelativePath { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public string? MimeType { get; set; }
|
||||
public long SizeBytes { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbUrlSize)]
|
||||
public string? OriginalUrl { get; set; }
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public string? OriginalFileName { get; set; }
|
||||
|
||||
public int? Width { get; set; }
|
||||
public int? Height { get; set; }
|
||||
public long? LenghtMilliseconds { get; set; }
|
||||
}
|
@@ -3,7 +3,7 @@ using Manager.Data.Entities.Audit;
|
||||
|
||||
namespace Manager.Data.Entities.LibraryContext;
|
||||
|
||||
[Auditable]
|
||||
[NoAudit]
|
||||
public class HttpCookieEntity : DateTimeBase
|
||||
{
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
|
Reference in New Issue
Block a user