From 8175e7988d6f956dc9d305512b56702d0fe2edd2 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 20 Nov 2021 12:20:11 -0600 Subject: [PATCH] =?UTF-8?q?refactor(dir):=20=E2=99=BB=20extract=20Aggregat?= =?UTF-8?q?eRootCore=20to=20resolve=20circular=20refs=20in=20Change=20mode?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{AggregateRoot.cs => AggregateRootCore.cs} | 2 +- .../Aggregates/Changes/FilterListChange.cs | 11 ++---- .../Changes/IChangeAggregateRoot.cs | 8 ---- .../Changes/IChangeAggregateRootCore.cs | 7 ++++ .../Aggregates/FilterLists/FilterList.cs | 38 ++++++++++--------- .../FilterListChangeTypeConfiguration.cs | 12 ++---- .../FilterListTypeConfiguration.cs | 6 ++- 7 files changed, 42 insertions(+), 42 deletions(-) rename services/Directory/FilterLists.Directory.Domain/Aggregates/{AggregateRoot.cs => AggregateRootCore.cs} (59%) delete mode 100644 services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRoot.cs create mode 100644 services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRoot.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs similarity index 59% rename from services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRoot.cs rename to services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs index 054c0d074..8d934f14c 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRoot.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs @@ -1,5 +1,5 @@ namespace FilterLists.Directory.Domain.Aggregates; -public abstract class AggregateRoot +public abstract class AggregateRootCore { } diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs index 15b651635..1f67175a5 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs @@ -2,15 +2,12 @@ namespace FilterLists.Directory.Domain.Aggregates.Changes; -public sealed class FilterListChange : Change, IChange +public sealed class FilterListChange : Change, IChange { - private FilterListChange() - { - } + private FilterListChange() { } - public FilterList? Current { get; private init; } - public FilterList? Before { get; private init; } - public FilterList? After { get; private init; } + public FilterListCore? Before { get; private init; } + public FilterListCore? After { get; private init; } public static FilterListChange Create(FilterList filterList, string? reason) { diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRoot.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRoot.cs deleted file mode 100644 index fb32592ae..000000000 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRoot.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace FilterLists.Directory.Domain.Aggregates.Changes; - -public interface IChange where TAggregate : AggregateRoot -{ - TAggregate? Current { get; } - TAggregate? Before { get; } - TAggregate? After { get; } -} diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs new file mode 100644 index 000000000..553d17fc5 --- /dev/null +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs @@ -0,0 +1,7 @@ +namespace FilterLists.Directory.Domain.Aggregates.Changes; + +public interface IChange where TAggregateRootCore : AggregateRootCore +{ + TAggregateRootCore? Before { get; } + TAggregateRootCore? After { get; } +} diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs index 92f362cb6..b94658c48 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs @@ -3,27 +3,31 @@ namespace FilterLists.Directory.Domain.Aggregates.FilterLists; -public sealed class FilterList : AggregateRoot, IRequireChangeApproval +public class FilterListCore : AggregateRootCore +{ + protected FilterListCore() { } + + public string Name { get; protected init; } = null!; + public string? Description { get; protected init; } + public License License { get; protected init; } = null!; + public Uri? HomeUrl { get; protected init; } + public Uri? OnionUrl { get; protected init; } + public Uri? PolicyUrl { get; protected init; } + public Uri? SubmissionUrl { get; protected init; } + public Uri? IssuesUrl { get; protected init; } + public Uri? ForumUrl { get; protected init; } + public Uri? ChatUrl { get; protected init; } + public string? EmailAddress { get; protected init; } + public Uri? DonateUrl { get; protected init; } + public IReadOnlyCollection ViewUrls { get; protected init; } = new HashSet(); +} + +public sealed class FilterList : FilterListCore, IRequireChangeApproval { private ICollection _changes = new HashSet(); - private FilterList() - { - } + private FilterList() { } - public string Name { get; private init; } = null!; - public string? Description { get; private init; } - public License License { get; private init; } = null!; - public Uri? HomeUrl { get; private init; } - public Uri? OnionUrl { get; private init; } - public Uri? PolicyUrl { get; private init; } - public Uri? SubmissionUrl { get; private init; } - public Uri? IssuesUrl { get; private init; } - public Uri? ForumUrl { get; private init; } - public Uri? ChatUrl { get; private init; } - public string? EmailAddress { get; private init; } - public Uri? DonateUrl { get; private init; } - public IReadOnlyCollection ViewUrls { get; private init; } = new HashSet(); public IReadOnlyCollection Changes => (IReadOnlyCollection)_changes; public static FilterList Create( diff --git a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListChangeTypeConfiguration.cs b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListChangeTypeConfiguration.cs index da039acb2..6ac477c5e 100644 --- a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListChangeTypeConfiguration.cs +++ b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListChangeTypeConfiguration.cs @@ -10,13 +10,9 @@ internal class FilterListChangeTypeConfiguration : IEntityTypeConfiguration builder) { builder.Property(nameof(Change.FilterListId)); - builder.HasOne(c => c.Current) - .WithMany(f => f.Changes) - .HasForeignKey(nameof(Change.FilterListId)); - - // TODO: share by configuring IChange - // TODO: serialize/deserialize json via value converter - builder.Ignore(c => c.Before); - builder.Ignore(c => c.After); + builder.Property(c => c.Before) + .HasColumnType("jsonb"); + builder.Property(c => c.After) + .HasColumnType("jsonb"); } } diff --git a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListTypeConfiguration.cs b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListTypeConfiguration.cs index a4298b110..d25e5df71 100644 --- a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListTypeConfiguration.cs +++ b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/EntityTypeConfigurations/FilterListTypeConfiguration.cs @@ -1,6 +1,7 @@ -using FilterLists.Directory.Domain.Aggregates.FilterLists; +using FilterLists.Directory.Infrastructure.Persistence.Queries.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using FilterList = FilterLists.Directory.Domain.Aggregates.FilterLists.FilterList; namespace FilterLists.Directory.Infrastructure.Persistence.Commands.EntityTypeConfigurations; @@ -9,6 +10,9 @@ internal class FilterListTypeConfiguration : IEntityTypeConfiguration builder) { builder.Property(nameof(Queries.Entities.FilterList.Id)); + builder.HasMany(c => c.Changes) + .WithOne() + .HasForeignKey(nameof(Change.FilterListId)); builder.Navigation(f => f.Changes) .AutoInclude(); builder.Navigation(f => f.ViewUrls)