refactor(dir): ♻ use FKs to link Changes to Aggregates

This commit is contained in:
Collin M. Barrett 2021-11-13 05:09:09 -06:00
parent 2c5f8363e1
commit fe87f5b4cf
11 changed files with 44 additions and 30 deletions

View file

@ -1,12 +0,0 @@
namespace FilterLists.Directory.Domain.Aggregates.Changes;
public enum AggregateRoot
{
FilterList,
Language,
License,
Maintainer,
Software,
Syntax,
Tag
}

View file

@ -1,4 +1,5 @@
using System.Text.Json;
using FilterLists.Directory.Domain.Aggregates.Licenses;
namespace FilterLists.Directory.Domain.Aggregates.Changes;
@ -8,20 +9,26 @@ private Change()
{
}
public Change(ChangeType type, AggregateRoot aggregateRoot, int aggregateRootId, JsonDocument? aggregate)
public Change(ChangeType type)
{
Type = type;
AggregateRoot = aggregateRoot;
AggregateRootId = aggregateRootId;
Aggregate = aggregate;
}
public ChangeType Type { get; private init; }
public AggregateRoot AggregateRoot { get; private init; }
public int AggregateRootId { get; private init; }
public JsonDocument? Aggregate { get; private init; }
public DateTime CreatedAt { get; private init; }
public DateTime? AppliedAt { get; private init; }
public DateTime? RejectedAt { get; private init; }
public string? RejectedReason { get; private init; }
public ChangeType Type { get; init; }
public JsonDocument? AggregateBefore { get; init; }
public JsonDocument? AggregateAfter { get; init; }
public DateTime CreatedAt { get; init; }
public string? CreatedReason { get; init; }
public DateTime? AppliedAt { get; init; }
public DateTime? RejectedAt { get; init; }
public string? RejectedReason { get; init; }
public FilterList? FilterList { get; init; }
//public Language? Language { get; }
public License? License { get; init; }
//public Maintainer? Maintainer { get; }
//public Software? Software { get; }
//public Syntax? Syntax { get; }
//public Tag? Tag { get; }
}

View file

@ -11,7 +11,6 @@ public class QueryDbContext : DbContext
static QueryDbContext()
{
NpgsqlConnection.GlobalTypeMapper.MapEnum<ChangeType>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<AggregateRoot>();
}
public QueryDbContext(DbContextOptions<QueryDbContext> options) : base(options)
@ -44,6 +43,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly,
type => type.Namespace == typeof(FilterListTypeConfiguration).Namespace);
modelBuilder.HasPostgresEnum<ChangeType>();
modelBuilder.HasPostgresEnum<AggregateRoot>();
}
}

View file

@ -5,17 +5,31 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public class Change
public record Change
{
public int Id { get; init; }
public ChangeType Type { get; init; }
public AggregateRoot AggregateRoot { get; init; }
public int AggregateRootId { get; init; }
public JsonDocument? Aggregate { get; init; }
public JsonDocument? AggregateBefore { get; init; }
public JsonDocument? AggregateAfter { get; init; }
public DateTime CreatedAt { get; init; }
public string? CreatedReason { get; init; }
public DateTime? AppliedAt { get; init; }
public DateTime? RejectedAt { get; init; }
public string? RejectedReason { get; init; }
public int? FilterListId { get; init; }
public FilterList? FilterList { get; }
public string? LanguageIso6391 { get; init; }
public Language? Language { get; }
public int? LicenseId { get; init; }
public License? License { get; }
public int? MaintainerId { get; init; }
public Maintainer? Maintainer { get; }
public int? SoftwareId { get; init; }
public Software? Software { get; }
public int? SyntaxId { get; init; }
public Syntax? Syntax { get; }
public int? TagId { get; init; }
public Tag? Tag { get; }
}
internal class UpdateConfiguration : IEntityTypeConfiguration<Change>

View file

@ -29,6 +29,7 @@ public record FilterList : AggregateRoot
public IEnumerable<Merge> IncludesFilterLists { get; init; } = new HashSet<Merge>();
public IEnumerable<Dependent> DependencyFilterLists { get; init; } = new HashSet<Dependent>();
public IEnumerable<Dependent> DependentFilterLists { get; init; } = new HashSet<Dependent>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class FilterListTypeConfiguration : AggregateRootTypeConfiguration<FilterList>

View file

@ -8,6 +8,7 @@ public record Language : AggregateRoot
public string Iso6391 { get; init; } = null!;
public string Name { get; init; } = null!;
public IEnumerable<FilterListLanguage> FilterListLanguages { get; init; } = new HashSet<FilterListLanguage>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class LanguageTypeConfiguration : AggregateRootTypeConfiguration<Language>

View file

@ -11,6 +11,7 @@ public record License : AggregateRoot
public bool PermitsDistribution { get; init; }
public bool PermitsCommercialUse { get; init; }
public IEnumerable<FilterList> FilterLists { get; init; } = new HashSet<FilterList>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class LicenseTypeConfiguration : AggregateRootTypeConfiguration<License>

View file

@ -9,6 +9,7 @@ public record Maintainer : AggregateRoot
public string? EmailAddress { get; init; }
public string? TwitterHandle { get; init; }
public IEnumerable<FilterListMaintainer> FilterListMaintainers { get; init; } = new HashSet<FilterListMaintainer>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class MaintainerTypeConfiguration : AggregateRootTypeConfiguration<Maintainer>

View file

@ -11,6 +11,7 @@ public record Software : AggregateRoot
public Uri? DownloadUrl { get; init; }
public bool SupportsAbpUrlScheme { get; init; }
public IEnumerable<SoftwareSyntax> SoftwareSyntaxes { get; init; } = new HashSet<SoftwareSyntax>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class SoftwareTypeConfiguration : AggregateRootTypeConfiguration<Software>

View file

@ -9,6 +9,7 @@ public record Syntax : AggregateRoot
public Uri? Url { get; init; }
public IEnumerable<FilterListSyntax> FilterListSyntaxes { get; init; } = new HashSet<FilterListSyntax>();
public IEnumerable<SoftwareSyntax> SoftwareSyntaxes { get; init; } = new HashSet<SoftwareSyntax>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class SyntaxTypeConfiguration : AggregateRootTypeConfiguration<Syntax>

View file

@ -7,6 +7,7 @@ public record Tag : AggregateRoot
public string Name { get; init; } = null!;
public string? Description { get; init; }
public IEnumerable<FilterListTag> FilterListTags { get; init; } = new HashSet<FilterListTag>();
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
}
internal class TagTypeConfiguration : AggregateRootTypeConfiguration<Tag>