mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(dir): ♻ ren AggregateRoot -> EntityRequiringApproval in Query context
This commit is contained in:
parent
4bd723486f
commit
f633a4a6d0
9 changed files with 30 additions and 29 deletions
|
|
@ -3,16 +3,16 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public abstract record AggregateRoot : Entity
|
||||
public abstract record EntityRequiringApproval : Entity
|
||||
{
|
||||
// TODO: change 'set' to 'init' when no longer seeding from json
|
||||
public bool IsApproved { get; set; }
|
||||
}
|
||||
|
||||
internal abstract class AggregateRootTypeConfiguration<TAggregateRoot> : IEntityTypeConfiguration<TAggregateRoot>
|
||||
where TAggregateRoot : AggregateRoot
|
||||
internal abstract class EntityRequiringApprovalTypeConfiguration<TEntityRequiringApproval>
|
||||
: IEntityTypeConfiguration<TEntityRequiringApproval> where TEntityRequiringApproval : EntityRequiringApproval
|
||||
{
|
||||
public virtual void Configure(EntityTypeBuilder<TAggregateRoot> builder)
|
||||
public virtual void Configure(EntityTypeBuilder<TEntityRequiringApproval> builder)
|
||||
{
|
||||
builder.HasQueryFilter(e => e.IsApproved);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record FilterList : AggregateRoot
|
||||
public record FilterList : EntityRequiringApproval
|
||||
{
|
||||
public string Name { get; init; } = default!;
|
||||
public string? Description { get; init; }
|
||||
|
|
@ -32,7 +32,7 @@ public record FilterList : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class FilterListTypeConfiguration : AggregateRootTypeConfiguration<FilterList>
|
||||
internal class FilterListTypeConfiguration : EntityRequiringApprovalTypeConfiguration<FilterList>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<FilterList> builder)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record Language : AggregateRoot
|
||||
public record Language : EntityRequiringApproval
|
||||
{
|
||||
public string Iso6391 { get; init; } = default!;
|
||||
public string Name { get; init; } = default!;
|
||||
|
|
@ -11,7 +11,7 @@ public record Language : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class LanguageTypeConfiguration : AggregateRootTypeConfiguration<Language>
|
||||
internal class LanguageTypeConfiguration : EntityRequiringApprovalTypeConfiguration<Language>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Language> builder)
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ public override void Configure(EntityTypeBuilder<Language> builder)
|
|||
.IsUnique();
|
||||
builder.HasIndex(l => l.Name)
|
||||
.IsUnique();
|
||||
builder.HasDataJsonFileAggregate<Language>();
|
||||
builder.HasDataJsonFileEntityRequiringApproval<Language>();
|
||||
base.Configure(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record License : AggregateRoot
|
||||
public record License : EntityRequiringApproval
|
||||
{
|
||||
public string Name { get; init; } = default!;
|
||||
public Uri? Url { get; init; }
|
||||
|
|
@ -14,7 +14,7 @@ public record License : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class LicenseTypeConfiguration : AggregateRootTypeConfiguration<License>
|
||||
internal class LicenseTypeConfiguration : EntityRequiringApprovalTypeConfiguration<License>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<License> builder)
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ public override void Configure(EntityTypeBuilder<License> builder)
|
|||
.HasDefaultValue(false);
|
||||
builder.Property(l => l.PermitsCommercialUse)
|
||||
.HasDefaultValue(false);
|
||||
builder.HasDataJsonFileAggregate<License>();
|
||||
builder.HasDataJsonFileEntityRequiringApproval<License>();
|
||||
base.Configure(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record Maintainer : AggregateRoot
|
||||
public record Maintainer : EntityRequiringApproval
|
||||
{
|
||||
public string Name { get; init; } = default!;
|
||||
public Uri? Url { get; init; }
|
||||
|
|
@ -12,13 +12,13 @@ public record Maintainer : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class MaintainerTypeConfiguration : AggregateRootTypeConfiguration<Maintainer>
|
||||
internal class MaintainerTypeConfiguration : EntityRequiringApprovalTypeConfiguration<Maintainer>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Maintainer> builder)
|
||||
{
|
||||
builder.HasIndex(m => m.Name)
|
||||
.IsUnique();
|
||||
builder.HasDataJsonFileAggregate<Maintainer>();
|
||||
builder.HasDataJsonFileEntityRequiringApproval<Maintainer>();
|
||||
base.Configure(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record Software : AggregateRoot
|
||||
public record Software : EntityRequiringApproval
|
||||
{
|
||||
public string Name { get; init; } = default!;
|
||||
public string? Description { get; init; }
|
||||
|
|
@ -14,7 +14,7 @@ public record Software : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class SoftwareTypeConfiguration : AggregateRootTypeConfiguration<Software>
|
||||
internal class SoftwareTypeConfiguration : EntityRequiringApprovalTypeConfiguration<Software>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Software> builder)
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ public override void Configure(EntityTypeBuilder<Software> builder)
|
|||
.IsUnique();
|
||||
builder.Property(s => s.SupportsAbpUrlScheme)
|
||||
.HasDefaultValue(false);
|
||||
builder.HasDataJsonFileAggregate<Software>();
|
||||
builder.HasDataJsonFileEntityRequiringApproval<Software>();
|
||||
base.Configure(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record Syntax : AggregateRoot
|
||||
public record Syntax : EntityRequiringApproval
|
||||
{
|
||||
public string Name { get; init; } = default!;
|
||||
public string? Description { get; init; }
|
||||
|
|
@ -12,13 +12,13 @@ public record Syntax : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class SyntaxTypeConfiguration : AggregateRootTypeConfiguration<Syntax>
|
||||
internal class SyntaxTypeConfiguration : EntityRequiringApprovalTypeConfiguration<Syntax>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Syntax> builder)
|
||||
{
|
||||
builder.HasIndex(s => s.Name)
|
||||
.IsUnique();
|
||||
builder.HasDataJsonFileAggregate<Syntax>();
|
||||
builder.HasDataJsonFileEntityRequiringApproval<Syntax>();
|
||||
base.Configure(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
|
||||
public record Tag : AggregateRoot
|
||||
public record Tag : EntityRequiringApproval
|
||||
{
|
||||
public string Name { get; init; } = default!;
|
||||
public string? Description { get; init; }
|
||||
|
|
@ -10,13 +10,13 @@ public record Tag : AggregateRoot
|
|||
public IEnumerable<Change> Changes { get; init; } = new HashSet<Change>();
|
||||
}
|
||||
|
||||
internal class TagTypeConfiguration : AggregateRootTypeConfiguration<Tag>
|
||||
internal class TagTypeConfiguration : EntityRequiringApprovalTypeConfiguration<Tag>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Tag> builder)
|
||||
{
|
||||
builder.HasIndex(t => t.Name)
|
||||
.IsUnique();
|
||||
builder.HasDataJsonFileAggregate<Tag>();
|
||||
builder.HasDataJsonFileEntityRequiringApproval<Tag>();
|
||||
base.Configure(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Npgsql;
|
||||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence;
|
||||
|
||||
|
|
@ -26,8 +25,8 @@ public static async Task MigrateAsync(this IHost host)
|
|||
|
||||
internal static class SeedConfigurationExtension
|
||||
{
|
||||
public static void HasDataJsonFileAggregate<TEntity>(this EntityTypeBuilder entityTypeBuilder)
|
||||
where TEntity : AggregateRoot
|
||||
public static void HasDataJsonFileEntityRequiringApproval<TEntity>(this EntityTypeBuilder entityTypeBuilder)
|
||||
where TEntity : EntityRequiringApproval
|
||||
{
|
||||
var entities = Deserialize<TEntity>();
|
||||
if (entities.Count == 0)
|
||||
|
|
@ -66,12 +65,14 @@ private static List<TEntity> Deserialize<TEntity>()
|
|||
}
|
||||
|
||||
var entitiesJson = File.ReadAllText(path);
|
||||
var entities = JsonSerializer.Deserialize<IEnumerable<TEntity>>(entitiesJson,
|
||||
var entities = JsonSerializer.Deserialize<IEnumerable<TEntity>>(
|
||||
entitiesJson,
|
||||
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
||||
return entities is null ? new List<TEntity>() : entities.ToList();
|
||||
}
|
||||
|
||||
private static void Approve<TAggregateRoot>(this TAggregateRoot entity) where TAggregateRoot : AggregateRoot
|
||||
private static void Approve<TEntityRequiringApproval>(this TEntityRequiringApproval entity)
|
||||
where TEntityRequiringApproval : EntityRequiringApproval
|
||||
{
|
||||
entity.IsApproved = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue