using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.API.Settings;
using PARR.Core.Common.RabbitServices;
using PARR.DAL.Services.Interfaces.Job;
using PARR.Domain.Common.Rabbit.Messages;
using PARR.Domain.Common.Roles;
using PARR.Domain.Entities.Base.History;
using PARR.Domain.Enums;
namespace PARR.API.Controllers.V1
{
///
/// Пересчитать все nextRun для JobGroup
///
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class JobGroupUpdateNextRunController : BaseApiController
{
private readonly IRabbitService mqService;
private readonly MqSettings mqSettings;
private readonly IJobGroupService jobGroupService;
public JobGroupUpdateNextRunController(
IRabbitService mqService,
MqSettings mqSettings,
IJobGroupService jobGroupService
)
{
this.mqService = mqService;
this.mqSettings = mqSettings;
this.jobGroupService = jobGroupService;
}
///
/// Обновить nextRun для всех шаблонах в JobGroup
///
///
[HttpPost(ApiRoutes.JobGroupUpdateNextRun.UpdateNextRun)]
public async Task UpdateNextRun([FromRoute] Guid jobGroupId)
{
var jobGroup = await jobGroupService.Get().AnyAsync(t => t.Id == jobGroupId);
if (!jobGroup)
return BadRequest(new Response(null, false, new List { new ErrorModel { Message = "Не найдена группа работ с ИД" } }));
var requestToMq = new NextRunUpdateMq
{
JobGroupId = jobGroupId,
Initiator = new HistoryInitiator
{
InitiatorComment = "Вручную отправлен запрос на обновление nextRun для группы работ",
InitiatorParrComponentId = ParrComponentsEnum.Api
}
};
var sendResult = await mqService.SendAsync(mqSettings.NextRun, new List