mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(dir): ♻ extract FilterListRecord
This commit is contained in:
parent
55422dbaf6
commit
6de36cfdca
5 changed files with 69 additions and 33 deletions
|
|
@ -2,25 +2,30 @@
|
|||
|
||||
namespace FilterLists.Directory.Domain.Aggregates.Changes;
|
||||
|
||||
public sealed class FilterListChange : Change, IChange<FilterListCore>
|
||||
public sealed class FilterListChange : Change, IChangeAggregate<FilterListRecord>
|
||||
{
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
namespace FilterLists.Directory.Domain.Aggregates.Changes;
|
||||
|
||||
public interface IChangeAggregate<out TAggregateRecord>
|
||||
{
|
||||
TAggregateRecord? Before { get; }
|
||||
TAggregateRecord? After { get; }
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
namespace FilterLists.Directory.Domain.Aggregates.Changes;
|
||||
|
||||
public interface IChange<out TAggregateRootCore> where TAggregateRootCore : AggregateRootCore
|
||||
{
|
||||
TAggregateRootCore? Before { get; }
|
||||
TAggregateRootCore? After { get; }
|
||||
}
|
||||
|
|
@ -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<FilterListViewUrl> ViewUrls { get; protected init; } = new HashSet<FilterListViewUrl>();
|
||||
}
|
||||
|
||||
public sealed class FilterList : FilterListCore, IRequireChangeApproval<FilterListChange>
|
||||
public sealed class FilterList : IRequireChangeApproval<FilterListChange>
|
||||
{
|
||||
private ICollection<FilterListChange> _changes = new HashSet<FilterListChange>();
|
||||
|
||||
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<FilterListViewUrl> ViewUrls { get; private init; } = new HashSet<FilterListViewUrl>();
|
||||
public IReadOnlyCollection<FilterListChange> Changes => (IReadOnlyCollection<FilterListChange>)_changes;
|
||||
|
||||
public static FilterList Create(
|
||||
|
|
|
|||
|
|
@ -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<FilterListViewUrl> 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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue