generator templates, отправка в MQ
This commit is contained in:
@@ -1,18 +1,37 @@
|
||||
using FluentValidation;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.BLL.Contracts;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Validators
|
||||
{
|
||||
public class GeneratorTemplateRequestValidator : AbstractValidator<GeneratorTemplateRequest>
|
||||
{
|
||||
public GeneratorTemplateRequestValidator()
|
||||
private readonly IApplicationService applicationService;
|
||||
|
||||
public GeneratorTemplateRequestValidator(IApplicationService applicationService)
|
||||
{
|
||||
this.applicationService = applicationService;
|
||||
|
||||
RuleFor(t => t.WorkId).NotEmpty();
|
||||
RuleFor(t => t.ApplicationId).NotEmpty();
|
||||
|
||||
RuleFor(t => t.ApplicationId)
|
||||
.MustAsync(async (entity, value, c) => await IsExistApplication(entity, value))
|
||||
.WithMessage("Нет приложения с таким Id.");
|
||||
|
||||
RuleFor(t => t.Ek).NotEmpty();
|
||||
RuleFor(t => t.Action).Must(t => t.ToLower() == GenerateTemplateActionsEnum.create.ToString() || t.ToLower() == GenerateTemplateActionsEnum.deactivate.ToString())
|
||||
|
||||
RuleFor(t => t.Action)
|
||||
.Must(t => t.ToLower() == GenerateTemplateActionsEnum.create.ToString() || t.ToLower() == GenerateTemplateActionsEnum.deactivate.ToString())
|
||||
.WithMessage($"Допустимые значения: {GenerateTemplateActionsEnum.create}, {GenerateTemplateActionsEnum.deactivate}");
|
||||
|
||||
}
|
||||
|
||||
//todo: сделать валидацию в тбл AppInWorks
|
||||
|
||||
private async Task<bool> IsExistApplication(GeneratorTemplateRequest request, Guid applicationId)
|
||||
{
|
||||
return await applicationService.GetAsync(applicationId) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user