fix(dir): 🐛 ICommandContext many-to-many configs

This commit is contained in:
Collin M. Barrett 2021-11-29 16:59:07 -06:00
parent eb0edd36aa
commit 723106e10c
2 changed files with 54 additions and 12 deletions

View file

@ -268,23 +268,23 @@ public async Task<Response> Handle(Command request, CancellationToken cancellati
}
if (request.ForkFilterListIds.Any(fid => !relatedFilterLists.Select(f => f.Id).Contains(fid)))
{
throw new ArgumentException("One or more ForkFilterListIds not found.", nameof(request.UpstreamFilterListIds));
throw new ArgumentException("One or more ForkFilterListIds not found.", nameof(request.ForkFilterListIds));
}
if (request.IncludedInFilterListIds.Any(fid => !relatedFilterLists.Select(f => f.Id).Contains(fid)))
{
throw new ArgumentException("One or more IncludedInFilterListIds not found.", nameof(request.UpstreamFilterListIds));
throw new ArgumentException("One or more IncludedInFilterListIds not found.", nameof(request.IncludedInFilterListIds));
}
if (request.IncludesFilterListIds.Any(fid => !relatedFilterLists.Select(f => f.Id).Contains(fid)))
{
throw new ArgumentException("One or more IncludesFilterListIds not found.", nameof(request.UpstreamFilterListIds));
throw new ArgumentException("One or more IncludesFilterListIds not found.", nameof(request.IncludesFilterListIds));
}
if (request.DependencyFilterListIds.Any(fid => !relatedFilterLists.Select(f => f.Id).Contains(fid)))
{
throw new ArgumentException("One or more DependencyFilterListIds not found.", nameof(request.UpstreamFilterListIds));
throw new ArgumentException("One or more DependencyFilterListIds not found.", nameof(request.DependencyFilterListIds));
}
if (request.DependentFilterListIds.Any(fid => !relatedFilterLists.Select(f => f.Id).Contains(fid)))
{
throw new ArgumentException("One or more DependentFilterListIds not found.", nameof(request.UpstreamFilterListIds));
throw new ArgumentException("One or more DependentFilterListIds not found.", nameof(request.DependentFilterListIds));
}
var filterList = FilterList.CreatePendingApproval(

View file

@ -16,25 +16,67 @@ public virtual void Configure(EntityTypeBuilder<FilterList> builder)
builder.HasMany(f => f.Syntaxes)
.WithMany(s => s.FilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(FilterListSyntax))}es"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(FilterListSyntax))}es");
e.Property<long>(nameof(FilterListSyntax.FilterListId));
e.Property<long>(nameof(FilterListSyntax.SyntaxId));
e.HasKey(nameof(FilterListSyntax.FilterListId), nameof(FilterListSyntax.SyntaxId));
});
builder.HasMany(f => f.Languages)
.WithMany(l => l.FilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(FilterListLanguage))}s"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(FilterListLanguage))}s");
e.Property<long>(nameof(FilterListLanguage.FilterListId));
e.Property<long>(nameof(FilterListLanguage.LanguageId));
e.HasKey(nameof(FilterListLanguage.FilterListId), nameof(FilterListLanguage.LanguageId));
});
builder.HasMany(f => f.Tags)
.WithMany(t => t.FilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(FilterListTag))}s"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(FilterListTag))}s");
e.Property<long>(nameof(FilterListTag.FilterListId));
e.Property<long>(nameof(FilterListTag.TagId));
e.HasKey(nameof(FilterListTag.FilterListId), nameof(FilterListTag.TagId));
});
builder.HasMany(f => f.Maintainers)
.WithMany(m => m.FilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(FilterListMaintainer))}s"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(FilterListMaintainer))}s");
e.Property<long>(nameof(FilterListMaintainer.FilterListId));
e.Property<long>(nameof(FilterListMaintainer.MaintainerId));
e.HasKey(nameof(FilterListMaintainer.FilterListId), nameof(FilterListMaintainer.MaintainerId));
});
builder.HasMany(f => f.UpstreamFilterLists)
.WithMany(f => f.ForkFilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(Fork))}s"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(Fork))}s");
e.Property<long>(nameof(Fork.UpstreamFilterListId));
e.Property<long>(nameof(Fork.ForkFilterListId));
e.HasKey(nameof(Fork.UpstreamFilterListId), nameof(Fork.ForkFilterListId));
});
builder.HasMany(f => f.IncludedInFilterLists)
.WithMany(f => f.IncludesFilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(Merge))}s"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(Merge))}s");
e.Property<long>(nameof(Merge.IncludedInFilterListId));
e.Property<long>(nameof(Merge.IncludesFilterListId));
e.HasKey(nameof(Merge.IncludedInFilterListId), nameof(Merge.IncludesFilterListId));
});
builder.HasMany(f => f.DependencyFilterLists)
.WithMany(f => f.DependentFilterLists)
.UsingEntity(e => e.ToTable($"{nr.RewriteName(nameof(Dependent))}s"));
.UsingEntity(e =>
{
e.ToTable($"{nr.RewriteName(nameof(Dependent))}s");
e.Property<long>(nameof(Dependent.DependencyFilterListId));
e.Property<long>(nameof(Dependent.DependentFilterListId));
e.HasKey(nameof(Dependent.DependencyFilterListId), nameof(Dependent.DependentFilterListId));
});
builder.HasMany(f => f.Changes)
.WithOne()
.HasForeignKey(nameof(Change.FilterListId));