feat(templateDistributor): заготовка
This commit is contained in:
@@ -2,6 +2,6 @@
|
||||
{
|
||||
public class DistributeRequest
|
||||
{
|
||||
public Guid ApplicationInWorkId { get; set; }
|
||||
public Guid JobGroupId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перераспределить шаблоны для регламентной работы
|
||||
/// Перераспределить шаблоны для группы работ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.Distributor.Distribute)]
|
||||
@@ -48,7 +48,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var requestToMq = new TemplateDistributorMq
|
||||
{
|
||||
ApplicationInWorkId = request.ApplicationInWorkId
|
||||
JobGroupId = request.JobGroupId
|
||||
};
|
||||
|
||||
var msg = JsonSerializer.Serialize(requestToMq);
|
||||
@@ -58,7 +58,7 @@ namespace PARR.API.Controllers.V1
|
||||
if (sendResult.IsSuccess)
|
||||
return Created("", new Response<string?>(null, true, new List<ErrorModel>(), "Отправлен запрос на перераспределение регламентных работ."));
|
||||
else
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message="Ошибка при отправке данных."} }));
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при отправке данных." } }));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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