From 522c204ecd5c5fdfaab68769eb50aeff6230a5ee Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Wed, 24 Nov 2021 07:23:16 -0600 Subject: [PATCH] =?UTF-8?q?refactor(dir):=20=E2=99=BB=20prefer=20IEnumerab?= =?UTF-8?q?le=20over=20IReadOnlyCollection=20for=20immutability=20(force?= =?UTF-8?q?=20copy-by-value=20to=20mutate=20element's=20props)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aggregates/Changes/IRequireChangeApproval.cs | 8 ++++---- .../Aggregates/FilterLists/FilterList.cs | 8 +++----- .../Aggregates/FilterLists/FilterListRecord.cs | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IRequireChangeApproval.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IRequireChangeApproval.cs index 699b48b59..702ea9928 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IRequireChangeApproval.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Changes/IRequireChangeApproval.cs @@ -2,9 +2,9 @@ public interface IRequireChangeApproval where TChange : Change { - public IReadOnlyCollection Changes { get; } - public IReadOnlyCollection PendingChanges => (IReadOnlyCollection)Changes.Where(c => c.ApprovedAt == null && c.RejectedAt == null); - public IReadOnlyCollection ApprovedChanges => (IReadOnlyCollection)Changes.Where(c => c.ApprovedAt != null); - public IReadOnlyCollection RejectedChanges => (IReadOnlyCollection)Changes.Where(c => c.RejectedAt != null); + public IEnumerable Changes { get; } + public IEnumerable PendingChanges => Changes.Where(c => c.ApprovedAt == null && c.RejectedAt == null); + public IEnumerable ApprovedChanges => Changes.Where(c => c.ApprovedAt != null); + public IEnumerable RejectedChanges => Changes.Where(c => c.RejectedAt != null); public bool IsApproved { get; } } diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs index fac24bfab..aeb9cd221 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterList.cs @@ -5,14 +5,12 @@ namespace FilterLists.Directory.Domain.Aggregates.FilterLists; public class FilterList : IRequireChangeApproval { - private ICollection _changes = new HashSet(); - 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 ViewUrls { get; private init; } = new HashSet(); + public virtual IEnumerable ViewUrls { get; private init; } = new HashSet(); 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 Changes => (IReadOnlyCollection)_changes; + public virtual IEnumerable Changes { get; private set; } = new HashSet(); 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(new[] { FilterListChange.Create(list, createReason) }); + list.Changes = new HashSet(new[] { FilterListChange.Create(list, createReason) }); return list; } } diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs index 0f9615e32..fe0abb81f 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListRecord.cs @@ -6,7 +6,7 @@ public record FilterListRecord( string Name, string? Description, License License, - IReadOnlyCollection ViewUrls, + IEnumerable ViewUrls, Uri? HomeUrl, Uri? OnionUrl, Uri? PolicyUrl,