diff options
| author | ivar <i@oiee.no> | 2025-12-03 21:49:20 +0100 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-12-03 21:49:20 +0100 |
| commit | cd70f54266d708867a1eb35870bc755bc5b2df32 (patch) | |
| tree | f0a8ec571ef3f345ac74293b4cb11918878b3ed5 /api/WhatApi/Tables | |
| parent | 5bd9ad8bd1740dcff179d66718532086304ca4c4 (diff) | |
| download | what-cd70f54266d708867a1eb35870bc755bc5b2df32.tar.xz what-cd70f54266d708867a1eb35870bc755bc5b2df32.zip | |
Refactor db
Diffstat (limited to 'api/WhatApi/Tables')
| -rw-r--r-- | api/WhatApi/Tables/AuditTrail.cs | 39 | ||||
| -rw-r--r-- | api/WhatApi/Tables/Content.cs | 24 | ||||
| -rw-r--r-- | api/WhatApi/Tables/IAuditableEntity.cs | 9 | ||||
| -rw-r--r-- | api/WhatApi/Tables/Place.cs | 25 | ||||
| -rw-r--r-- | api/WhatApi/Tables/User.cs | 31 |
5 files changed, 0 insertions, 128 deletions
diff --git a/api/WhatApi/Tables/AuditTrail.cs b/api/WhatApi/Tables/AuditTrail.cs deleted file mode 100644 index 9613af4..0000000 --- a/api/WhatApi/Tables/AuditTrail.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace WhatApi.Tables; - -public class AuditTrail -{ - public Guid Id { get; init; } - public Guid? UserId { get; init; } - public required string EntityName { get; init; } - public string? PrimaryKey { get; set; } - public TrailType TrailType { get; set; } - public DateTimeOffset DateUtc { get; init; } - - public Dictionary<string, object?> OldValues { get; init; } = []; - public Dictionary<string, object?> NewValues { get; init; } = []; - public List<string> ChangedColumns { get; init; } = []; -} - -public class AuditTrailConfiguration : IEntityTypeConfiguration<AuditTrail> -{ - public void Configure(EntityTypeBuilder<AuditTrail> builder) - { - builder.ToTable("audit_trails"); - builder.HasIndex(e => e.EntityName); - builder.Property(e => e.EntityName).HasMaxLength(100).IsRequired(); - builder.Property(e => e.PrimaryKey).HasMaxLength(100); - builder.Property(e => e.DateUtc).IsRequired(); - builder.Property(e => e.TrailType).HasConversion<string>(); - builder.Property(e => e.OldValues).HasColumnType("jsonb"); - builder.Property(e => e.NewValues).HasColumnType("jsonb"); - builder.Property(e => e.ChangedColumns).HasColumnType("jsonb"); - } -} - -public enum TrailType : byte -{ - None = 0, - Create = 1, - Update = 2, - Delete = 3 -}
\ No newline at end of file diff --git a/api/WhatApi/Tables/Content.cs b/api/WhatApi/Tables/Content.cs deleted file mode 100644 index 0b26b82..0000000 --- a/api/WhatApi/Tables/Content.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Net; - -namespace WhatApi.Tables; - -public class Content : IAuditableEntity -{ - public Guid Id { get; set; } - public required string Mime { get; set; } - public Guid BlobId { get; set; } - public required IPAddress Ip { get; set; } - public DateTimeOffset CreatedAtUtc { get; set; } - public DateTimeOffset? UpdatedAtUtc { get; set; } - public Guid CreatedBy { get; set; } - public Guid? UpdatedBy { get; set; } -} - -public class ContentConfiguration : IEntityTypeConfiguration<Content> -{ - public void Configure(EntityTypeBuilder<Content> builder) { - builder.HasKey(x => x.Id); - builder.Property(x => x.Mime).HasMaxLength(100).IsRequired(); - builder.ToTable("content"); - } -}
\ No newline at end of file diff --git a/api/WhatApi/Tables/IAuditableEntity.cs b/api/WhatApi/Tables/IAuditableEntity.cs deleted file mode 100644 index a11e7f2..0000000 --- a/api/WhatApi/Tables/IAuditableEntity.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace WhatApi.Tables; - -public interface IAuditableEntity -{ - public DateTimeOffset CreatedAtUtc { get; set; } - public DateTimeOffset? UpdatedAtUtc { get; set; } - public Guid CreatedBy { get; set; } - public Guid? UpdatedBy { get; set; } -}
\ No newline at end of file diff --git a/api/WhatApi/Tables/Place.cs b/api/WhatApi/Tables/Place.cs deleted file mode 100644 index 969007b..0000000 --- a/api/WhatApi/Tables/Place.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace WhatApi.Tables; - -public class Place : IAuditableEntity -{ - public Guid Id { get; set; } - public Guid ContentId { get; set; } - public Content Content { get; set; } = null!; - public required Point Location { get; set; } - public DateTimeOffset CreatedAtUtc { get; set; } - public DateTimeOffset? UpdatedAtUtc { get; set; } - public Guid CreatedBy { get; set; } - public Guid? UpdatedBy { get; set; } -} - -public class PlaceConfiguration : IEntityTypeConfiguration<Place> -{ - public void Configure(EntityTypeBuilder<Place> builder) { - builder.ToTable("place"); - builder.HasKey(x => x.Id); - builder.Property(x => x.Location).IsRequired(); - builder.HasOne(x => x.Content); - builder.Property(x => x.Location).HasColumnType($"geometry(point,{Constants.Wgs84SpatialReferenceId})"); - builder.HasIndex(x => x.Location).HasMethod("gist"); - } -} diff --git a/api/WhatApi/Tables/User.cs b/api/WhatApi/Tables/User.cs deleted file mode 100644 index 9044439..0000000 --- a/api/WhatApi/Tables/User.cs +++ /dev/null @@ -1,31 +0,0 @@ -using WhatApi.Extras; - -namespace WhatApi.Tables; - -public class User : IAuditableEntity -{ - public Guid Id { get; set; } - public required string Name { get; set; } - public required string Email { get; set; } - - [AuditTrailIgnore] - public required string Password { get; set; } - public DateTimeOffset? LastSeen { get; set; } - public IEnumerable<Place> Places { get; set; } = null!; - public DateTimeOffset CreatedAtUtc { get; set; } - public DateTimeOffset? UpdatedAtUtc { get; set; } - public Guid CreatedBy { get; set; } - public Guid? UpdatedBy { get; set; } -} - -public class UserConfiguration : IEntityTypeConfiguration<User> -{ - public void Configure(EntityTypeBuilder<User> builder) { - builder.HasKey(x => x.Id); - builder.Property(x => x.Name).HasMaxLength(50); - builder.Property(x => x.Email).HasMaxLength(100); - builder.Property(x => x.Password).HasMaxLength(100); - builder.HasMany(x => x.Places); - builder.ToTable("user"); - } -}
\ No newline at end of file |
