mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(dir): ♻ extract AggregateRootCore to resolve circular refs in Change model
This commit is contained in:
parent
cee5db6952
commit
8175e7988d
7 changed files with 42 additions and 42 deletions
|
|
@ -1,5 +1,5 @@
|
|||
namespace FilterLists.Directory.Domain.Aggregates;
|
||||
|
||||
public abstract class AggregateRoot
|
||||
public abstract class AggregateRootCore
|
||||
{
|
||||
}
|
||||
|
|
@ -2,15 +2,12 @@
|
|||
|
||||
namespace FilterLists.Directory.Domain.Aggregates.Changes;
|
||||
|
||||
public sealed class FilterListChange : Change, IChange<FilterList>
|
||||
public sealed class FilterListChange : Change, IChange<FilterListCore>
|
||||
{
|
||||
private FilterListChange()
|
||||
{
|
||||
}
|
||||
private FilterListChange() { }
|
||||
|
||||
public FilterList? Current { get; private init; }
|
||||
public FilterList? Before { get; private init; }
|
||||
public FilterList? After { get; private init; }
|
||||
public FilterListCore? Before { get; private init; }
|
||||
public FilterListCore? After { get; private init; }
|
||||
|
||||
public static FilterListChange Create(FilterList filterList, string? reason)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
namespace FilterLists.Directory.Domain.Aggregates.Changes;
|
||||
|
||||
public interface IChange<out TAggregate> where TAggregate : AggregateRoot
|
||||
{
|
||||
TAggregate? Current { get; }
|
||||
TAggregate? Before { get; }
|
||||
TAggregate? After { get; }
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
namespace FilterLists.Directory.Domain.Aggregates.Changes;
|
||||
|
||||
public interface IChange<out TAggregateRootCore> where TAggregateRootCore : AggregateRootCore
|
||||
{
|
||||
TAggregateRootCore? Before { get; }
|
||||
TAggregateRootCore? After { get; }
|
||||
}
|
||||
|
|
@ -3,27 +3,31 @@
|
|||
|
||||
namespace FilterLists.Directory.Domain.Aggregates.FilterLists;
|
||||
|
||||
public sealed class FilterList : AggregateRoot, IRequireChangeApproval<FilterListChange>
|
||||
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>
|
||||
{
|
||||
private ICollection<FilterListChange> _changes = new HashSet<FilterListChange>();
|
||||
|
||||
private FilterList()
|
||||
{
|
||||
}
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -10,13 +10,9 @@ internal class FilterListChangeTypeConfiguration : IEntityTypeConfiguration<Filt
|
|||
public virtual void Configure(EntityTypeBuilder<FilterListChange> builder)
|
||||
{
|
||||
builder.Property<int>(nameof(Change.FilterListId));
|
||||
builder.HasOne(c => c.Current)
|
||||
.WithMany(f => f.Changes)
|
||||
.HasForeignKey(nameof(Change.FilterListId));
|
||||
|
||||
// TODO: share by configuring IChange<TAggregate>
|
||||
// TODO: serialize/deserialize json via value converter
|
||||
builder.Ignore(c => c.Before);
|
||||
builder.Ignore(c => c.After);
|
||||
builder.Property(c => c.Before)
|
||||
.HasColumnType("jsonb");
|
||||
builder.Property(c => c.After)
|
||||
.HasColumnType("jsonb");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using FilterLists.Directory.Domain.Aggregates.FilterLists;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using FilterList = FilterLists.Directory.Domain.Aggregates.FilterLists.FilterList;
|
||||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Commands.EntityTypeConfigurations;
|
||||
|
||||
|
|
@ -9,6 +10,9 @@ internal class FilterListTypeConfiguration : IEntityTypeConfiguration<FilterList
|
|||
public virtual void Configure(EntityTypeBuilder<FilterList> builder)
|
||||
{
|
||||
builder.Property<int>(nameof(Queries.Entities.FilterList.Id));
|
||||
builder.HasMany(c => c.Changes)
|
||||
.WithOne()
|
||||
.HasForeignKey(nameof(Change.FilterListId));
|
||||
builder.Navigation(f => f.Changes)
|
||||
.AutoInclude();
|
||||
builder.Navigation(f => f.ViewUrls)
|
||||
|
|
|
|||
Loading…
Reference in a new issue