mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(dir): ♻ prefer IEnumerable over IReadOnlyCollection for immutability (force copy-by-value to mutate element's props)
This commit is contained in:
parent
c56168f5f0
commit
522c204ecd
3 changed files with 8 additions and 10 deletions
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
public interface IRequireChangeApproval<out TChange> where TChange : Change
|
||||
{
|
||||
public IReadOnlyCollection<TChange> Changes { get; }
|
||||
public IReadOnlyCollection<TChange> PendingChanges => (IReadOnlyCollection<TChange>)Changes.Where(c => c.ApprovedAt == null && c.RejectedAt == null);
|
||||
public IReadOnlyCollection<TChange> ApprovedChanges => (IReadOnlyCollection<TChange>)Changes.Where(c => c.ApprovedAt != null);
|
||||
public IReadOnlyCollection<TChange> RejectedChanges => (IReadOnlyCollection<TChange>)Changes.Where(c => c.RejectedAt != null);
|
||||
public IEnumerable<TChange> Changes { get; }
|
||||
public IEnumerable<TChange> PendingChanges => Changes.Where(c => c.ApprovedAt == null && c.RejectedAt == null);
|
||||
public IEnumerable<TChange> ApprovedChanges => Changes.Where(c => c.ApprovedAt != null);
|
||||
public IEnumerable<TChange> RejectedChanges => Changes.Where(c => c.RejectedAt != null);
|
||||
public bool IsApproved { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,12 @@ namespace FilterLists.Directory.Domain.Aggregates.FilterLists;
|
|||
|
||||
public class FilterList : IRequireChangeApproval<FilterListChange>
|
||||
{
|
||||
private ICollection<FilterListChange> _changes = new HashSet<FilterListChange>();
|
||||
|
||||
protected FilterList() { }
|
||||
|
||||
public string Name { get; private init; } = null!;
|
||||
public string? Description { get; private init; }
|
||||
public virtual License License { get; private init; } = null!;
|
||||
public virtual IReadOnlyCollection<FilterListViewUrl> ViewUrls { get; private init; } = new HashSet<FilterListViewUrl>();
|
||||
public virtual IEnumerable<FilterListViewUrl> ViewUrls { get; private init; } = new HashSet<FilterListViewUrl>();
|
||||
public Uri? HomeUrl { get; private init; }
|
||||
public Uri? OnionUrl { get; private init; }
|
||||
public Uri? PolicyUrl { get; private init; }
|
||||
|
|
@ -22,7 +20,7 @@ protected FilterList() { }
|
|||
public Uri? ChatUrl { get; private init; }
|
||||
public string? EmailAddress { get; private init; }
|
||||
public Uri? DonateUrl { get; private init; }
|
||||
public virtual IReadOnlyCollection<FilterListChange> Changes => (IReadOnlyCollection<FilterListChange>)_changes;
|
||||
public virtual IEnumerable<FilterListChange> Changes { get; private set; } = new HashSet<FilterListChange>();
|
||||
public bool IsApproved { get; private init; }
|
||||
|
||||
public static FilterList CreatePendingApproval(
|
||||
|
|
@ -73,7 +71,7 @@ public static FilterList CreatePendingApproval(
|
|||
ViewUrls = urls,
|
||||
IsApproved = false
|
||||
};
|
||||
list._changes = new HashSet<FilterListChange>(new[] { FilterListChange.Create(list, createReason) });
|
||||
list.Changes = new HashSet<FilterListChange>(new[] { FilterListChange.Create(list, createReason) });
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ public record FilterListRecord(
|
|||
string Name,
|
||||
string? Description,
|
||||
License License,
|
||||
IReadOnlyCollection<FilterListViewUrl> ViewUrls,
|
||||
IEnumerable<FilterListViewUrl> ViewUrls,
|
||||
Uri? HomeUrl,
|
||||
Uri? OnionUrl,
|
||||
Uri? PolicyUrl,
|
||||
|
|
|
|||
Loading…
Reference in a new issue