mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(dir): ✨ capture 'After' change on FilterList create
This commit is contained in:
parent
afe57772b3
commit
9c5cb0cdae
2 changed files with 10 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace FilterLists.Directory.Domain.Aggregates.FilterLists;
|
|||
|
||||
public sealed class FilterList : AggregateRoot, IRequireChangeApproval<FilterListChange>
|
||||
{
|
||||
private readonly ICollection<FilterListChange> _changes = new HashSet<FilterListChange>();
|
||||
private ICollection<FilterListChange> _changes = new HashSet<FilterListChange>();
|
||||
|
||||
private FilterList()
|
||||
{
|
||||
|
|
@ -24,12 +24,7 @@ private FilterList()
|
|||
public string? EmailAddress { get; private init; }
|
||||
public Uri? DonateUrl { get; private init; }
|
||||
public IReadOnlyCollection<FilterListViewUrl> ViewUrls { get; private init; } = new HashSet<FilterListViewUrl>();
|
||||
|
||||
public IReadOnlyCollection<FilterListChange> Changes
|
||||
{
|
||||
get => (IReadOnlyCollection<FilterListChange>)_changes;
|
||||
private init => _changes = (ICollection<FilterListChange>)value;
|
||||
}
|
||||
public IReadOnlyCollection<FilterListChange> Changes => (IReadOnlyCollection<FilterListChange>)_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<FilterListChange>(new[] { FilterListChange.Create(createReason) })
|
||||
ViewUrls = urls
|
||||
};
|
||||
list._changes = new HashSet<FilterListChange>(new[] { FilterListChange.Create(list, createReason) });
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue