From 6de36cfdcac5cf9f7c75e9c7531c918b2366ac6f Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 20 Nov 2021 15:10:33 -0600 Subject: [PATCH] =?UTF-8?q?refactor(dir):=20=E2=99=BB=20extract=20FilterLi?= =?UTF-8?q?stRecord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aggregates/Changes/FilterListChange.cs | 17 ++++++--- .../Aggregates/Changes/IChangeAggregate.cs | 7 ++++ .../Changes/IChangeAggregateRootCore.cs | 7 ---- .../Aggregates/FilterLists/FilterList.cs | 34 +++++++---------- .../FilterLists/FilterListRecord.cs | 37 +++++++++++++++++++ 5 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregate.cs delete mode 100644 services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs create mode 100644 services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs index 1f67175a5..ab51648f5 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs @@ -2,25 +2,30 @@ namespace FilterLists.Directory.Domain.Aggregates.Changes; -public sealed class FilterListChange : Change, IChange +public sealed class FilterListChange : Change, IChangeAggregate { private FilterListChange() { } - public FilterListCore? Before { get; private init; } - public FilterListCore? After { get; private init; } + public FilterListRecord? Before { get; private init; } + public FilterListRecord? After { get; private init; } public static FilterListChange Create(FilterList filterList, string? reason) { - return new FilterListChange { After = filterList, Reason = reason }; + return new FilterListChange { After = FilterListRecord.FromFilterList(filterList), Reason = reason }; } public static FilterListChange Update(FilterList before, FilterList after, string? reason) { - return new FilterListChange { Before = before, After = after, Reason = reason }; + return new FilterListChange + { + Before = FilterListRecord.FromFilterList(before), + After = FilterListRecord.FromFilterList(after), + Reason = reason + }; } public static FilterListChange Delete(FilterList filterList, string? reason) { - return new FilterListChange { Before = filterList, Reason = reason }; + return new FilterListChange { Before = FilterListRecord.FromFilterList(filterList), Reason = reason }; } } diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregate.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregate.cs new file mode 100644 index 000000000..02b8d7467 --- /dev/null +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregate.cs @@ -0,0 +1,7 @@ +namespace FilterLists.Directory.Domain.Aggregates.Changes; + +public interface IChangeAggregate +{ + TAggregateRecord? Before { get; } + TAggregateRecord? After { get; } +} diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs deleted file mode 100644 index 553d17fc5..000000000 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IChangeAggregateRootCore.cs +++ /dev/null @@ -1,7 +0,0 @@ -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 b94658c48..cf5098ca2 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs @@ -3,31 +3,25 @@ namespace FilterLists.Directory.Domain.Aggregates.FilterLists; -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 +public sealed class FilterList : IRequireChangeApproval { private ICollection _changes = new HashSet(); 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.Domain/Aggregates/FilterLists/FilterListRecord.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs new file mode 100644 index 000000000..069c87f03 --- /dev/null +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs @@ -0,0 +1,37 @@ +using FilterLists.Directory.Domain.Aggregates.Licenses; + +namespace FilterLists.Directory.Domain.Aggregates.FilterLists; + +public record FilterListRecord( + string Name, + string? Description, + License License, + Uri? HomeUrl, + Uri? OnionUrl, + Uri? PolicyUrl, + Uri? SubmissionUrl, + Uri? IssuesUrl, + Uri? ForumUrl, + Uri? ChatUrl, + string? EmailAddress, + Uri? DonateUrl, + IReadOnlyCollection ViewUrls) +{ + public static FilterListRecord FromFilterList(FilterList filterList) + { + return new FilterListRecord( + filterList.Name, + filterList.Description, + filterList.License, + filterList.HomeUrl, + filterList.OnionUrl, + filterList.PolicyUrl, + filterList.SubmissionUrl, + filterList.IssuesUrl, + filterList.ForumUrl, + filterList.ChatUrl, + filterList.EmailAddress, + filterList.DonateUrl, + filterList.ViewUrls); + } +}