feat(dal, templateMatcher): изменена логика работы Shortcodes сервиса в сторону самостоятельной дозагрузки данных из БД, в Template сервис добавлен метод атомарного резервирования шаблона для TemplateMatcher

This commit is contained in:
Mikhail Kuznetsov
2026-01-16 18:26:06 +10:00
parent 99a491ede8
commit d91877453a
25 changed files with 822 additions and 509 deletions

View File

@@ -0,0 +1,60 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Requests;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.DAL.DomainServices.Shortcodes;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
public class ShortcodeApplyController : BaseApiController
{
private readonly ILogger<ShortcodeController> logger;
private readonly IShortcodesService shortcodesService;
private readonly ITemplateService templateService;
public ShortcodeApplyController(
ILogger<ShortcodeController> logger,
IShortcodesService shortcodesService,
ITemplateService templateService
)
{
this.logger = logger;
this.shortcodesService = shortcodesService;
this.templateService = templateService;
}
/// <summary>
/// Получить список всех переменных составляющих
/// </summary>
/// <returns></returns>
[HttpPost(ApiRoutes.ShortcodeApply.Apply)]
public async Task<IActionResult> Apply([FromBody] ShortcodeApplyRequest request)
{
var template = await templateService.Get()
.Include(t => t.Unit)
.Include(t => t.UnitsInTemplate)
.Include(t => t.Unit)
.Include(t => t.Job)
.ThenInclude(t => t!.Group)
.ThenInclude(t => t!.GroupType)
.Include(t => t.Job)
.ThenInclude(t => t!.Tnk)
.AsNoTracking()
.FirstOrDefaultAsync(t => t.Id == request.TemplateId);
if (template == null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.TemplateId), Message = $"Шаблон имеющий Id = {request.TemplateId} не найден" } }));
var aplyingShortCodes = await shortcodesService.ApplyShortcodesAsync(request.Content, template);
var response = new ShortcodeApplyResponse { Content = aplyingShortCodes };
return Ok(new Response<ShortcodeApplyResponse>(response, true));
}
}
}