feat(api,templateActivator): обновлена логика templateActivator

This commit is contained in:
Mikhail Trubnikov
2025-11-26 14:34:03 +10:00
parent 2823823784
commit 276f534636
19 changed files with 520 additions and 313 deletions

View File

@@ -1,16 +1,43 @@
using FluentValidation;
using PARR.API.Contracts.V1.Requests;
using PARR.Constants;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.API.Validators
{
public class TemplateActivatorRequestValidator : AbstractValidator<TemplateActivatorRequest>
{
public TemplateActivatorRequestValidator()
public TemplateActivatorRequestValidator(
ITemplateService templateService,
IJobService jobService,
IJobGroupService jobGroupService
)
{
RuleFor(t => t.Action).Must(action =>
Enum.IsDefined(typeof(TemplateActivatorActionsEnum), action)
).WithMessage("Некорректное значение action");
RuleFor(t => t.EntityType).Must(type =>
Enum.IsDefined(typeof(SyncTaskEntityTypeEnum), type)
).WithMessage("Некорректное значение EntityType");
RuleFor(t => t.EsppObject).Must(obj =>
Enum.IsDefined(typeof(TemplateActivatorEsppObjectTypesEnum), obj)
).WithMessage("Некорректное значение EsppObject");
RuleFor(t => t.Id)
.MustAsync(async (entity, value, c) =>
{
switch (entity.EntityType)
{
case SyncTaskEntityTypeEnum.JobGroup:
return await jobGroupService.GetAsync(value) != null;
case SyncTaskEntityTypeEnum.Job:
return await jobService.GetAsync(value) != null;
case SyncTaskEntityTypeEnum.Template:
return await templateService.GetAsync(value) != null;
}
return false;
})
.WithMessage("Некорректное значение Id");
}
}
}