feat(templateDistributor): заготовка
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
|
||||
namespace PARR.API.Validators
|
||||
{
|
||||
public class DistributeRequestValidator : AbstractValidator<DistributeRequest>
|
||||
{
|
||||
private readonly IApplicationsInWorkService applicationsInWorkService;
|
||||
|
||||
public DistributeRequestValidator(IApplicationsInWorkService applicationsInWorkService)
|
||||
public DistributeRequestValidator(IJobGroupService jobGroupService)
|
||||
{
|
||||
this.applicationsInWorkService = applicationsInWorkService;
|
||||
|
||||
|
||||
RuleFor(t => t.ApplicationInWorkId).NotEmpty().MustAsync(async (entity, value, c) =>
|
||||
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
|
||||
{
|
||||
var appInWork = await applicationsInWorkService.GetAsync(value);
|
||||
|
||||
return appInWork != null;
|
||||
return await jobGroupService.Get().FirstOrDefaultAsync(t => t.Id == value) != null;
|
||||
}).WithMessage("Недопустимое значение");
|
||||
|
||||
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
|
||||
{
|
||||
var jobGroup = await jobGroupService.Get()
|
||||
.Include(t => t.DistributionConfig)
|
||||
.FirstOrDefaultAsync(t => t.Id == value);
|
||||
|
||||
return jobGroup != null && jobGroup.IsAutoDistributionEnabled && jobGroup.DistributionConfig != null;
|
||||
}).WithMessage("Отсутствуют настройки автораспределения");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user