From 9c5cb0cdae6bc777f2a1e94be9b0a8b8d90c191c Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 19 Nov 2021 04:16:19 -0600 Subject: [PATCH] =?UTF-8?q?feat(dir):=20=E2=9C=A8=20capture=20'After'=20ch?= =?UTF-8?q?ange=20on=20FilterList=20create?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aggregates/Changes/FilterListChange.cs | 4 ++-- .../Aggregates/FilterLists/FilterList.cs | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs index e9af78ac3..15b651635 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/FilterListChange.cs @@ -12,9 +12,9 @@ private FilterListChange() public FilterList? Before { get; private init; } public FilterList? After { get; private init; } - public static FilterListChange Create(string? reason) + public static FilterListChange Create(FilterList filterList, string? reason) { - return new FilterListChange { Reason = reason }; + return new FilterListChange { After = filterList, Reason = reason }; } public static FilterListChange Update(FilterList before, FilterList after, string? reason) diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs index c6b1700b5..ec94e5ffd 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs @@ -5,7 +5,7 @@ namespace FilterLists.Directory.Domain.Aggregates.FilterLists; public sealed class FilterList : AggregateRoot, IRequireChangeApproval { - private readonly ICollection _changes = new HashSet(); + private ICollection _changes = new HashSet(); private FilterList() { @@ -24,12 +24,7 @@ private FilterList() public string? EmailAddress { get; private init; } public Uri? DonateUrl { get; private init; } public IReadOnlyCollection ViewUrls { get; private init; } = new HashSet(); - - public IReadOnlyCollection Changes - { - get => (IReadOnlyCollection)_changes; - private init => _changes = (ICollection)value; - } + public IReadOnlyCollection Changes => (IReadOnlyCollection)_changes; public static FilterList Create( string name, @@ -47,13 +42,14 @@ public static FilterList Create( IEnumerable<(short SegmentNumber, short Primariness, Uri Url)> viewUrls, string? createReason) { - var urls = viewUrls.Select(u => FilterListViewUrl.Create(u.SegmentNumber, u.Primariness, u.Url)).ToList(); + var urls = viewUrls.Select(u => FilterListViewUrl.Create(u.SegmentNumber, u.Primariness, u.Url)) + .ToList(); if (urls.Count == 0) { throw new ArgumentException("At lest one view URL is required.", nameof(viewUrls)); } - return new FilterList + var list = new FilterList { Name = name, Description = description, @@ -67,8 +63,9 @@ public static FilterList Create( ChatUrl = chatUrl, EmailAddress = emailAddress, DonateUrl = donateUrl, - ViewUrls = urls, - Changes = new HashSet(new[] { FilterListChange.Create(createReason) }) + ViewUrls = urls }; + list._changes = new HashSet(new[] { FilterListChange.Create(list, createReason) }); + return list; } }