Revert preview feature

This commit is contained in:
Michael Bucari-Tovo 2022-06-26 10:42:52 -06:00
parent 888967be31
commit 3ce1f94f87
18 changed files with 58 additions and 45 deletions

View file

@ -7,7 +7,7 @@ using Dinah.Core;
namespace DtoImporterService
{
public abstract class ImporterBase<TValidate> where TValidate : IValidator
public abstract class ImporterBase<T>
{
protected LibationContext DbContext { get; }
@ -18,13 +18,13 @@ namespace DtoImporterService
}
/// <summary>LONG RUNNING. call with await Task.Run</summary>
public int Import(IEnumerable<ImportItem> param) => Run(DoImport, param);
public int Import(T param) => Run(DoImport, param);
public TResult Run<TResult>(Func<IEnumerable<ImportItem>, TResult> func, IEnumerable<ImportItem> param)
public TResult Run<TResult>(Func<T, TResult> func, T param)
{
try
{
var exceptions = TValidate.Validate(param.Select(i => i.DtoItem));
var exceptions = Validate(param);
if (exceptions is not null && exceptions.Any())
throw new AggregateException($"Importer validation failed", exceptions);
}
@ -46,6 +46,16 @@ namespace DtoImporterService
}
}
protected abstract int DoImport(IEnumerable<ImportItem> elements);
protected abstract int DoImport(T elements);
public abstract IEnumerable<Exception> Validate(T param);
}
public abstract class ItemsImporterBase : ImporterBase<IEnumerable<ImportItem>>
{
protected ItemsImporterBase(LibationContext context) : base(context) { }
protected abstract IValidator Validator { get; }
public sealed override IEnumerable<Exception> Validate(IEnumerable<ImportItem> importItems)
=> Validator.Validate(importItems.Select(i => i.DtoItem));
}
}