generator templates, отправка в MQ
This commit is contained in:
@@ -1,21 +1,32 @@
|
||||
using FluentValidation;
|
||||
using AutoMapper;
|
||||
using FluentValidation;
|
||||
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.BLL.Domain.Mq;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class GeneratorTemplateController : BaseApiController
|
||||
{
|
||||
private readonly IValidator<GeneratorTemplateRequest> validator;
|
||||
private readonly IMqGeneratorTemplateService mqGeneratorTemplateService;
|
||||
private readonly IUriService uriService;
|
||||
|
||||
public GeneratorTemplateController(
|
||||
IValidator<GeneratorTemplateRequest> validator
|
||||
IValidator<GeneratorTemplateRequest> validator,
|
||||
IMqGeneratorTemplateService mqGeneratorTemplateService,
|
||||
IUriService uriService
|
||||
)
|
||||
{
|
||||
this.validator = validator;
|
||||
this.mqGeneratorTemplateService = mqGeneratorTemplateService;
|
||||
this.uriService = uriService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,9 +40,26 @@ namespace PARR.API.Controllers.V1
|
||||
if (!resultValidate.IsValid)
|
||||
return BadRequest(new Response(resultValidate.Errors));
|
||||
|
||||
// Todo: проверить есть ли в бд такие ворк и апп
|
||||
|
||||
var obj = new GeneratorTemplateMq
|
||||
{
|
||||
Action = request.Action,
|
||||
ApplicationId = request.ApplicationId,
|
||||
Ek = request.Ek,
|
||||
WorkId = request.WorkId
|
||||
};
|
||||
|
||||
return Ok();
|
||||
var msg = JsonSerializer.Serialize(obj);
|
||||
|
||||
var result = mqGeneratorTemplateService.SendMsg(msg);
|
||||
|
||||
if (!result)
|
||||
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>(), "Отправлен запрос на генерацию шаблонов."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user