2023-09-20 11:59:09 +10:00
|
|
|
|
using FluentValidation;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Requests;
|
|
|
|
|
|
using PARR.BLL.Contracts;
|
2023-09-20 15:27:13 +10:00
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
2023-09-20 11:59:09 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Validators
|
|
|
|
|
|
{
|
|
|
|
|
|
public class GeneratorTemplateRequestValidator : AbstractValidator<GeneratorTemplateRequest>
|
|
|
|
|
|
{
|
2023-09-20 15:27:13 +10:00
|
|
|
|
private readonly IApplicationService applicationService;
|
|
|
|
|
|
|
|
|
|
|
|
public GeneratorTemplateRequestValidator(IApplicationService applicationService)
|
2023-09-20 11:59:09 +10:00
|
|
|
|
{
|
2023-09-20 15:27:13 +10:00
|
|
|
|
this.applicationService = applicationService;
|
|
|
|
|
|
|
2023-09-20 11:59:09 +10:00
|
|
|
|
RuleFor(t => t.WorkId).NotEmpty();
|
2023-09-20 15:27:13 +10:00
|
|
|
|
|
|
|
|
|
|
RuleFor(t => t.ApplicationId)
|
|
|
|
|
|
.MustAsync(async (entity, value, c) => await IsExistApplication(entity, value))
|
|
|
|
|
|
.WithMessage("Нет приложения с таким Id.");
|
|
|
|
|
|
|
2023-09-20 11:59:09 +10:00
|
|
|
|
RuleFor(t => t.Ek).NotEmpty();
|
2023-09-20 15:27:13 +10:00
|
|
|
|
|
|
|
|
|
|
RuleFor(t => t.Action)
|
|
|
|
|
|
.Must(t => t.ToLower() == GenerateTemplateActionsEnum.create.ToString() || t.ToLower() == GenerateTemplateActionsEnum.deactivate.ToString())
|
2023-09-20 11:59:09 +10:00
|
|
|
|
.WithMessage($"Допустимые значения: {GenerateTemplateActionsEnum.create}, {GenerateTemplateActionsEnum.deactivate}");
|
2023-09-20 15:27:13 +10:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//todo: сделать валидацию в тбл AppInWorks
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<bool> IsExistApplication(GeneratorTemplateRequest request, Guid applicationId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await applicationService.GetAsync(applicationId) != null;
|
2023-09-20 11:59:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|