Bll MqService

This commit is contained in:
Mikhail Trubnikov
2023-09-21 09:37:36 +10:00
parent d50cb20c95
commit 096a990669
11 changed files with 109 additions and 38 deletions

View File

@@ -5,7 +5,9 @@ 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 System.Text.Json;
namespace PARR.API.Controllers.V1
@@ -13,18 +15,21 @@ namespace PARR.API.Controllers.V1
public class GeneratorTemplateController : BaseApiController
{
private readonly IValidator<GeneratorTemplateRequest> validator;
private readonly IMqGeneratorTemplateService mqGeneratorTemplateService;
private readonly IMqService mqService;
private readonly IUriService uriService;
private readonly MqSettings mqSettings;
public GeneratorTemplateController(
IValidator<GeneratorTemplateRequest> validator,
IMqGeneratorTemplateService mqGeneratorTemplateService,
IUriService uriService
IMqService mqService,
IUriService uriService,
MqSettings mqSettings
)
{
this.validator = validator;
this.mqGeneratorTemplateService = mqGeneratorTemplateService;
this.mqService = mqService;
this.uriService = uriService;
this.mqSettings = mqSettings;
}
/// <summary>
@@ -38,8 +43,6 @@ namespace PARR.API.Controllers.V1
if (!resultValidate.IsValid)
return BadRequest(new Response(resultValidate.Errors));
// Todo: проверить есть ли в бд такие ворк и апп
var obj = new GeneratorTemplateMq
{
Action = request.Action,
@@ -50,9 +53,9 @@ namespace PARR.API.Controllers.V1
var msg = JsonSerializer.Serialize(obj);
var result = mqGeneratorTemplateService.SendMsg(msg);
var result = mqService.Send(mqSettings.GenerateTemplates, new[] { msg });
if (!result)
if (!result.IsSuccess)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при отправке данных." } }));
var createdUri = uriService.GetAllUri(ApiRoutes.Template.GetAll);