2024-07-05 12:42:01 +10:00
|
|
|
|
using FluentValidation;
|
2026-01-21 16:28:17 +10:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
using PARR.API.Contracts.V1.Requests;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
using PARR.Core.Repositories.Interfaces.Job;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Validators
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DistributeRequestValidator : AbstractValidator<DistributeRequest>
|
|
|
|
|
|
{
|
2026-04-30 10:35:31 +10:00
|
|
|
|
public DistributeRequestValidator(IJobGroupRepository jobGroupService)
|
2024-07-05 12:42:01 +10:00
|
|
|
|
{
|
2026-01-21 16:28:17 +10:00
|
|
|
|
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return await jobGroupService.Get().FirstOrDefaultAsync(t => t.Id == value) != null;
|
|
|
|
|
|
}).WithMessage("Недопустимое значение");
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
2026-01-21 16:28:17 +10:00
|
|
|
|
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
|
2024-07-05 12:42:01 +10:00
|
|
|
|
{
|
2026-01-21 16:28:17 +10:00
|
|
|
|
var jobGroup = await jobGroupService.Get()
|
|
|
|
|
|
.Include(t => t.DistributionConfig)
|
|
|
|
|
|
.FirstOrDefaultAsync(t => t.Id == value);
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
2026-01-21 16:28:17 +10:00
|
|
|
|
return jobGroup != null && jobGroup.IsAutoDistributionEnabled && jobGroup.DistributionConfig != null;
|
|
|
|
|
|
}).WithMessage("Отсутствуют настройки автораспределения");
|
2024-07-05 12:42:01 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|