mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(dir): ♻ decouple FilterListViewUrl app model from domain model
This commit is contained in:
parent
e6f6ae56b2
commit
4ddeb60d07
3 changed files with 14 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ namespace FilterLists.Directory.Application.Commands;
|
|||
public static class CreateList
|
||||
{
|
||||
public record Command(string Name,
|
||||
ICollection<FilterListViewUrl> ViewUrls,
|
||||
IEnumerable<FilterListViewUrl> ViewUrls,
|
||||
string? Description = default,
|
||||
int? LicenseId = default,
|
||||
Uri? HomeUrl = default,
|
||||
|
|
@ -22,6 +22,8 @@ public record Command(string Name,
|
|||
Uri? DonateUrl = default,
|
||||
string? ChangeReason = default) : IRequest<Response>;
|
||||
|
||||
public record FilterListViewUrl(short SegmentNumber, short Primariness, Uri Url);
|
||||
|
||||
internal class Validator : AbstractValidator<Command>
|
||||
{
|
||||
public Validator()
|
||||
|
|
@ -62,7 +64,7 @@ public async Task<Response> Handle(Command request, CancellationToken cancellati
|
|||
request.ChatUrl,
|
||||
request.EmailAddress,
|
||||
request.DonateUrl,
|
||||
request.ViewUrls,
|
||||
request.ViewUrls.Select(u => (u.SegmentNumber, u.Primariness, u.Url)),
|
||||
request.ChangeReason);
|
||||
_commandContext.FilterLists.Add(filterList);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ private FilterList()
|
|||
public IReadOnlyCollection<FilterListChange> Changes
|
||||
{
|
||||
get => (IReadOnlyCollection<FilterListChange>)_changes;
|
||||
init => _changes = (ICollection<FilterListChange>)value;
|
||||
private init => _changes = (ICollection<FilterListChange>)value;
|
||||
}
|
||||
|
||||
public static FilterList Create(
|
||||
|
|
@ -44,10 +44,11 @@ public static FilterList Create(
|
|||
Uri? chatUrl,
|
||||
string? emailAddress,
|
||||
Uri? donateUrl,
|
||||
ICollection<FilterListViewUrl> viewUrls,
|
||||
IEnumerable<(short SegmentNumber, short Primariness, Uri Url)> viewUrls,
|
||||
string? createReason)
|
||||
{
|
||||
if (viewUrls.Count == 0)
|
||||
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));
|
||||
}
|
||||
|
|
@ -66,7 +67,7 @@ public static FilterList Create(
|
|||
ChatUrl = chatUrl,
|
||||
EmailAddress = emailAddress,
|
||||
DonateUrl = donateUrl,
|
||||
ViewUrls = (IReadOnlyCollection<FilterListViewUrl>)viewUrls,
|
||||
ViewUrls = urls,
|
||||
Changes = new HashSet<FilterListChange>(new[] { FilterListChange.Create(createReason) })
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,9 @@ private FilterListViewUrl() { }
|
|||
public short SegmentNumber { get; private init; }
|
||||
public short Primariness { get; private init; }
|
||||
public Uri Url { get; private init; } = null!;
|
||||
|
||||
internal static FilterListViewUrl Create(short segmentNumber, short primariness, Uri url)
|
||||
{
|
||||
return new FilterListViewUrl { SegmentNumber = segmentNumber, Primariness = primariness, Url = url };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue