feat(api): TemplateActivatorController отправка запросов на активацию/деактивацию шаблонов/расписаний
This commit is contained in:
@@ -325,6 +325,18 @@
|
|||||||
|
|
||||||
public const string getParam = "{id}";
|
public const string getParam = "{id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Активатор/деактиватор шаблонов/расписаний
|
||||||
|
/// </summary>
|
||||||
|
public static class TemplateActivator
|
||||||
|
{
|
||||||
|
public const string SendRequest = Base + "/jobs/" + appInWorkId + "/template-activator";
|
||||||
|
|
||||||
|
public const string appInWorkId = "{applicationInWorkId}";
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static class Application
|
public static class Application
|
||||||
|
|||||||
12
PARR.API/Contracts/V1/Requests/TemplateActivatorRequest.cs
Normal file
12
PARR.API/Contracts/V1/Requests/TemplateActivatorRequest.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using PARR.Constants;
|
||||||
|
|
||||||
|
namespace PARR.API.Contracts.V1.Requests
|
||||||
|
{
|
||||||
|
public class TemplateActivatorRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Действие по активации/деактивации
|
||||||
|
/// </summary>
|
||||||
|
public TemplateActivatorActionsEnum Action { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
82
PARR.API/Controllers/V1/TemplateActivatorController.cs
Normal file
82
PARR.API/Controllers/V1/TemplateActivatorController.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using PARR.API.Contracts.V1;
|
||||||
|
using PARR.API.Contracts.V1.Requests;
|
||||||
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
|
using PARR.API.Controllers.V1.Base;
|
||||||
|
using PARR.API.Services.Interfaces;
|
||||||
|
using PARR.API.Settings;
|
||||||
|
using PARR.BLL.Domain.Mq;
|
||||||
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Отправка запросов на активацию/деактивацию шаблонов/расписаний
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class TemplateActivatorController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly IValidator<TemplateActivatorRequest> validator;
|
||||||
|
private readonly IMqService mqService;
|
||||||
|
private readonly IUriService uriService;
|
||||||
|
private readonly MqSettings mqSettings;
|
||||||
|
private readonly IApplicationsInWorkService applicationsInWorkService;
|
||||||
|
|
||||||
|
public TemplateActivatorController(
|
||||||
|
IValidator<TemplateActivatorRequest> validator,
|
||||||
|
IMqService mqService,
|
||||||
|
IUriService uriService,
|
||||||
|
MqSettings mqSettings,
|
||||||
|
IApplicationsInWorkService applicationsInWorkService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.validator = validator;
|
||||||
|
this.mqService = mqService;
|
||||||
|
this.uriService = uriService;
|
||||||
|
this.mqSettings = mqSettings;
|
||||||
|
this.applicationsInWorkService = applicationsInWorkService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Отправить запрос на активацию/деактивацию шаблонов/расписаний
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationInWorkId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(ApiRoutes.TemplateActivator.SendRequest)]
|
||||||
|
public async Task<IActionResult> SendRequest([FromRoute] Guid applicationInWorkId, [FromBody] TemplateActivatorRequest request)
|
||||||
|
{
|
||||||
|
var resultValidate = await validator.ValidateAsync(request);
|
||||||
|
if (!resultValidate.IsValid)
|
||||||
|
return BadRequest(new Response(resultValidate.Errors));
|
||||||
|
|
||||||
|
var appInWork = await applicationsInWorkService.GetAsync(applicationInWorkId);
|
||||||
|
|
||||||
|
if (appInWork == null)
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(applicationInWorkId), Message = "Некорректное значение" } }));
|
||||||
|
|
||||||
|
|
||||||
|
var mqRequest = new TemplateActivatorMq
|
||||||
|
{
|
||||||
|
ApplicationInWorkId = applicationInWorkId,
|
||||||
|
Action = request.Action
|
||||||
|
};
|
||||||
|
|
||||||
|
var msg = JsonSerializer.Serialize(mqRequest);
|
||||||
|
|
||||||
|
var sendResult = mqService.Send(mqSettings.TemplateActivator, new[] { msg });
|
||||||
|
|
||||||
|
if (!sendResult.IsSuccess)
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при отправке данных." } }));
|
||||||
|
|
||||||
|
var createdUri = uriService.GetAllUri(ApiRoutes.Template.GetAll);
|
||||||
|
|
||||||
|
return Created(createdUri, new Response<string?>(null, true, new List<ErrorModel>(), "Отправлен запрос активатору шаблонов/расписаний."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ namespace PARR.API.Settings
|
|||||||
{
|
{
|
||||||
public MqGenerateTemplates GenerateTemplates { get; set; } = new MqGenerateTemplates();
|
public MqGenerateTemplates GenerateTemplates { get; set; } = new MqGenerateTemplates();
|
||||||
public MqTemplateDistributor TemplateDistributor { get; set; } = new MqTemplateDistributor();
|
public MqTemplateDistributor TemplateDistributor { get; set; } = new MqTemplateDistributor();
|
||||||
|
public MqTemplateActivator TemplateActivator { get; set; } = new MqTemplateActivator();
|
||||||
public MqStatistics Statistics { get; set; } = new MqStatistics();
|
public MqStatistics Statistics { get; set; } = new MqStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +26,14 @@ namespace PARR.API.Settings
|
|||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MqTemplateActivator : IMqSettings
|
||||||
|
{
|
||||||
|
public string HostName { get; set; } = string.Empty;
|
||||||
|
public string QueueName { get; set; } = string.Empty;
|
||||||
|
public string User { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
public class MqStatistics
|
public class MqStatistics
|
||||||
{
|
{
|
||||||
public StatMqAuth StatMqAuth { get; set; } = new StatMqAuth();
|
public StatMqAuth StatMqAuth { get; set; } = new StatMqAuth();
|
||||||
|
|||||||
16
PARR.API/Validators/TemplateActivatorRequestValidator.cs
Normal file
16
PARR.API/Validators/TemplateActivatorRequestValidator.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using PARR.API.Contracts.V1.Requests;
|
||||||
|
using PARR.Constants;
|
||||||
|
|
||||||
|
namespace PARR.API.Validators
|
||||||
|
{
|
||||||
|
public class TemplateActivatorRequestValidator : AbstractValidator<TemplateActivatorRequest>
|
||||||
|
{
|
||||||
|
public TemplateActivatorRequestValidator()
|
||||||
|
{
|
||||||
|
RuleFor(t => t.Action).Must(action =>
|
||||||
|
Enum.IsDefined(typeof(TemplateActivatorActionsEnum), action)
|
||||||
|
).WithMessage("Некорректное значение action");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,9 @@
|
|||||||
"TemplateDistributor": {
|
"TemplateDistributor": {
|
||||||
"HostName": "10.99.253.216"
|
"HostName": "10.99.253.216"
|
||||||
},
|
},
|
||||||
|
"TemplateActivator": {
|
||||||
|
"HostName": "10.99.253.216"
|
||||||
|
},
|
||||||
"Statistics": {
|
"Statistics": {
|
||||||
"StatMqAuth": {
|
"StatMqAuth": {
|
||||||
"HostName": "10.99.253.216"
|
"HostName": "10.99.253.216"
|
||||||
|
|||||||
@@ -51,6 +51,12 @@
|
|||||||
"User": "template_distributor_writer",
|
"User": "template_distributor_writer",
|
||||||
"Password": "KGgsdfu%%44qqwew"
|
"Password": "KGgsdfu%%44qqwew"
|
||||||
},
|
},
|
||||||
|
"TemplateActivator": {
|
||||||
|
"HostName": "parr-rabbitmq",
|
||||||
|
"QueueName": "parr-template-activator",
|
||||||
|
"User": "template_activator_writer",
|
||||||
|
"Password": "Gfkjhsdg*%fsdf"
|
||||||
|
},
|
||||||
"Statistics": {
|
"Statistics": {
|
||||||
"StatMqAuth": {
|
"StatMqAuth": {
|
||||||
"HostName": "parr-rabbitmq",
|
"HostName": "parr-rabbitmq",
|
||||||
|
|||||||
@@ -8,42 +8,42 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Активировать все шаблоны
|
/// Активировать все шаблоны
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ActivateAllTemplates,
|
ActivateAllTemplates = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Активировать шаблоны у которых активировано расписание
|
/// Активировать шаблоны у которых активировано расписание
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ActivateTemplatesWithActiveSchedules,
|
ActivateTemplatesWithActiveSchedules = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Деактивировать все шаблоны
|
/// Деактивировать все шаблоны
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DeactivateAllTemplates,
|
DeactivateAllTemplates = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Деактивировать шаблоны у которынх деактивировано расписание
|
/// Деактивировать шаблоны у которынх деактивировано расписание
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DeactivateTemplatesWithDeactivationSchedules,
|
DeactivateTemplatesWithDeactivationSchedules = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Активировать все расписания
|
/// Активировать все расписания
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ActivateAllSchedules,
|
ActivateAllSchedules = 4,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Деактивировать все расписания
|
/// Деактивировать все расписания
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DeactivateAllSchedules,
|
DeactivateAllSchedules = 5,
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Активировать все расписания у которых активированы шаблоны
|
/// Активировать все расписания у которых активированы шаблоны
|
||||||
///
|
///
|
||||||
ActivateSchedulesWithActiveTemplates,
|
ActivateSchedulesWithActiveTemplates = 6,
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Деактивировать все расписания у которых деактивированы шаблоны
|
/// Деактивировать все расписания у которых деактивированы шаблоны
|
||||||
///
|
///
|
||||||
DeactivateSchedulesWithDeactivationTemplates
|
DeactivateSchedulesWithDeactivationTemplates = 7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user