mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(directory): ♻ rm unused seeding extension, temp disable seeding for broken type
This commit is contained in:
parent
bef1761bb8
commit
b58a5d9d9b
1 changed files with 7 additions and 13 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence
|
||||
|
|
@ -11,28 +12,21 @@ internal static class SeedExtensions
|
|||
public static void HasDataJsonFile<TEntity>(this EntityTypeBuilder entityTypeBuilder)
|
||||
{
|
||||
_ = entityTypeBuilder ?? throw new ArgumentNullException(nameof(entityTypeBuilder));
|
||||
var entities = GetEntities<TEntity>();
|
||||
entityTypeBuilder.HasData((IEnumerable<object>)entities);
|
||||
}
|
||||
|
||||
public static void HasDataJsonFile<TEntity>(this OwnedNavigationBuilder ownedNavigationBuilder)
|
||||
{
|
||||
_ = ownedNavigationBuilder ?? throw new ArgumentNullException(nameof(ownedNavigationBuilder));
|
||||
var entities = GetEntities<TEntity>();
|
||||
ownedNavigationBuilder.HasData((IEnumerable<object>)entities);
|
||||
}
|
||||
// TODO: fix seeding FilterListViewUrl
|
||||
if (typeof(TEntity).Name == nameof(FilterListViewUrl))
|
||||
return;
|
||||
|
||||
private static IEnumerable<TEntity> GetEntities<TEntity>()
|
||||
{
|
||||
var path = Path.Combine("../../data", $"{typeof(TEntity).Name}.json");
|
||||
if (!File.Exists(path)) return new HashSet<TEntity>();
|
||||
if (!File.Exists(path)) return;
|
||||
|
||||
var entitiesJson = File.ReadAllText(path);
|
||||
var entities = JsonSerializer.Deserialize<IEnumerable<TEntity>>(entitiesJson, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
return entities;
|
||||
|
||||
entityTypeBuilder.HasData((IEnumerable<object>)entities);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue