2026-06-30 16:12:52 +10:00
|
|
|
|
using FluentValidation;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Requests;
|
|
|
|
|
|
using PARR.Core.Repositories.Interfaces;
|
2026-07-03 11:17:48 +10:00
|
|
|
|
using PARR.Core.Repositories.Interfaces.JobGroupRepositories;
|
|
|
|
|
|
using PARR.Core.Repositories.Interfaces.JobRepositories;
|
2026-06-30 16:12:52 +10:00
|
|
|
|
using PARR.Domain.Enums;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Validators
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MatchTemplatesRequestValidator : AbstractValidator<MatchTemplatesRequest>
|
|
|
|
|
|
{
|
|
|
|
|
|
public MatchTemplatesRequestValidator(
|
|
|
|
|
|
IJobGroupRepository jobGroupRepository,
|
|
|
|
|
|
IJobRepository jobRepository,
|
|
|
|
|
|
ITemplateRepository templateRepository
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
RuleFor(t => t.ObjectId)
|
|
|
|
|
|
.NotNull()
|
|
|
|
|
|
.NotEmpty()
|
|
|
|
|
|
.WithMessage("Идентификатор объекта не может быть пустым.");
|
|
|
|
|
|
|
|
|
|
|
|
RuleFor(t => t)
|
|
|
|
|
|
.MustAsync(async (request, cancellation) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return request.EntityType switch
|
|
|
|
|
|
{
|
|
|
|
|
|
SyncTaskEntityTypeEnum.JobGroup =>
|
|
|
|
|
|
await jobGroupRepository.Get().AsNoTracking().AnyAsync(t => t.Id == request.ObjectId, cancellation),
|
|
|
|
|
|
|
|
|
|
|
|
SyncTaskEntityTypeEnum.Job =>
|
|
|
|
|
|
await jobRepository.Get().AsNoTracking().AnyAsync(t => t.Id == request.ObjectId && t.Group!.GroupType!.IsJobGroupAutoControl == false, cancellation),
|
|
|
|
|
|
|
|
|
|
|
|
SyncTaskEntityTypeEnum.Template =>
|
|
|
|
|
|
false, // TODO: Синхронизировать шаблоны нельзя
|
|
|
|
|
|
|
|
|
|
|
|
_ => false
|
|
|
|
|
|
};
|
|
|
|
|
|
})
|
|
|
|
|
|
.WithMessage(request => request.EntityType switch
|
|
|
|
|
|
{
|
|
|
|
|
|
SyncTaskEntityTypeEnum.Template => "Синхронизация шаблонов пока не поддерживается.",
|
|
|
|
|
|
SyncTaskEntityTypeEnum.Job => "Объект не найден или данные работы нельзя отправить на синхронизацию.",
|
|
|
|
|
|
_ => "Не найден объект с переданным ИД."
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|