feat(api,templateActivator): обновлена логика templateActivator
This commit is contained in:
@@ -4,5 +4,6 @@ namespace PARR.TemplateActivator;
|
||||
|
||||
internal interface IValidatorService
|
||||
{
|
||||
Task<bool> IsValidApplicationInWorkAsync(Guid applicationInWorkId);
|
||||
//Task<bool> IsValidApplicationInWorkAsync(Guid applicationInWorkId);
|
||||
Task<bool> IsValidObjectIdAsync(Guid id, SyncTaskEntityTypeEnum entityType);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.Base;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
|
||||
namespace PARR.TemplateActivator;
|
||||
|
||||
internal class ValidatorService : IValidatorService
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
@@ -18,25 +24,44 @@ internal class ValidatorService : IValidatorService
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> IsValidApplicationInWorkAsync(Guid applicationInWorkId)
|
||||
public async Task<bool> IsValidObjectIdAsync(Guid id, SyncTaskEntityTypeEnum entityType)
|
||||
{
|
||||
switch (entityType)
|
||||
{
|
||||
case (SyncTaskEntityTypeEnum.JobGroup):
|
||||
return await IsValidAync<IJobGroupService, JobGroup>(id);
|
||||
|
||||
case (SyncTaskEntityTypeEnum.Job):
|
||||
return await IsValidAync<IJobService, Job>(id);
|
||||
|
||||
case (SyncTaskEntityTypeEnum.Template):
|
||||
return await IsValidAync<ITemplateService, Template>(id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private async Task<bool> IsValidAync<TService, TEntity>(Guid id)
|
||||
where TService : class, IBaseService<TEntity>
|
||||
where TEntity : class, IBase
|
||||
{
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService<IApplicationsInWorkService>();
|
||||
|
||||
var service = scope.ServiceProvider.GetService<TService>();
|
||||
if (service == null)
|
||||
throw new Exception($"Не найден сервис: {nameof(IApplicationsInWorkService)}");
|
||||
throw new Exception($"Не найден сервис: {typeof(TService).Name}");
|
||||
|
||||
var appInWork = await service.Get()
|
||||
.FirstOrDefaultAsync(t => t.Id == applicationInWorkId);
|
||||
var obj = await service.GetAsync(id);
|
||||
|
||||
if (appInWork == null)
|
||||
if (obj == null)
|
||||
{
|
||||
logger.LogError($"Не найдена регалментная работа {nameof(applicationInWorkId)}: {applicationInWorkId}");
|
||||
logger.LogError($"Не объект {nameof(id)}: {id} в {typeof(TService).Name}");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user