2023-10-04 15:22:06 +10:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using FluentValidation;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using PARR.API.Contracts.V1;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Requests;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Requests.Queries;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses.Base;
|
2023-10-04 13:41:33 +10:00
|
|
|
|
using PARR.API.Controllers.V1.Base;
|
2023-10-04 15:22:06 +10:00
|
|
|
|
using PARR.API.Extensions;
|
|
|
|
|
|
using PARR.API.Services.Interfaces;
|
|
|
|
|
|
using PARR.DAL.DomainModels;
|
|
|
|
|
|
using PARR.DAL.Models;
|
|
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
2023-10-04 13:41:33 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
|
|
|
|
{
|
|
|
|
|
|
public class RobotTemplateHistoryController : BaseApiController
|
|
|
|
|
|
{
|
2023-10-04 15:22:06 +10:00
|
|
|
|
private readonly IValidator<RobotTemplateHistoryRequest> validator;
|
|
|
|
|
|
private readonly ITemplateService templateService;
|
|
|
|
|
|
private readonly IRobotTemplateHistoryService historyService;
|
|
|
|
|
|
private readonly IMapper mapper;
|
|
|
|
|
|
private readonly IUriService uriService;
|
2023-10-04 13:41:33 +10:00
|
|
|
|
|
2023-10-04 15:22:06 +10:00
|
|
|
|
public RobotTemplateHistoryController(
|
|
|
|
|
|
IValidator<RobotTemplateHistoryRequest> validator,
|
|
|
|
|
|
ITemplateService templateService,
|
|
|
|
|
|
IRobotTemplateHistoryService historyService,
|
|
|
|
|
|
IMapper mapper,
|
|
|
|
|
|
IUriService uriService
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.validator = validator;
|
|
|
|
|
|
this.templateService = templateService;
|
|
|
|
|
|
this.historyService = historyService;
|
|
|
|
|
|
this.mapper = mapper;
|
|
|
|
|
|
this.uriService = uriService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Получить историю робота шаблонов
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="paginationQuery"></param>
|
|
|
|
|
|
/// <param name="filter"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet(ApiRoutes.RobotTemplateHistory.GetAll)]
|
|
|
|
|
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] RobotTemplateHistoryQuery filter)
|
|
|
|
|
|
{
|
|
|
|
|
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
|
|
|
|
|
|
|
|
|
|
|
IQueryable<RobotTemplateHistory> query = historyService.Get()
|
|
|
|
|
|
.Include(t => t.Template)
|
|
|
|
|
|
.Include(t => t.RobotHistoryLevel)
|
|
|
|
|
|
.OrderByDescending(t => t.DateCreated).ThenBy(t => t.IdSeries);
|
|
|
|
|
|
|
|
|
|
|
|
if (filter.IdSeries != null)
|
|
|
|
|
|
query = query.Where(t => t.IdSeries == filter.IdSeries);
|
|
|
|
|
|
|
|
|
|
|
|
if (filter.TemplateId != null)
|
|
|
|
|
|
query = query.Where(t => t.TemplateId == filter.TemplateId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var history = await historyService.GetPage(query, paginationFilter).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (!history.Any())
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
|
|
var response = mapper.Map<List<RobotTemplateHistoryResponse>>(history);
|
|
|
|
|
|
var paginationResponse = new PagedResponse<RobotTemplateHistoryResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(paginationResponse);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Добавить историю робота шаблонов
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost(ApiRoutes.RobotTemplateHistory.Create)]
|
|
|
|
|
|
public async Task<IActionResult> Create([FromBody] RobotTemplateHistoryRequest request)
|
|
|
|
|
|
{
|
|
|
|
|
|
var resultValidate = await validator.ValidateAsync(request);
|
|
|
|
|
|
if (!resultValidate.IsValid)
|
|
|
|
|
|
return BadRequest(new Response(resultValidate.Errors));
|
|
|
|
|
|
|
|
|
|
|
|
var template = await templateService.GetAsync(request.TemplateId);
|
|
|
|
|
|
|
|
|
|
|
|
if (template == null)
|
|
|
|
|
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {request.TemplateId}" } }));
|
|
|
|
|
|
|
|
|
|
|
|
if (request.IdSeries == null)
|
|
|
|
|
|
request.IdSeries = Guid.NewGuid();
|
|
|
|
|
|
|
2023-10-05 16:56:02 +10:00
|
|
|
|
//var historyItem = new RobotTemplateHistory
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Id = Guid.NewGuid(),
|
|
|
|
|
|
// HistoryLevel = request.HistoryLevel,
|
|
|
|
|
|
// RobotMessage = request.RobotMessage,
|
|
|
|
|
|
// EsppMessage = request.EsppMessage,
|
|
|
|
|
|
// TemplateId = request.TemplateId,
|
|
|
|
|
|
// TemplateStatusCode = template.StatusCode,
|
|
|
|
|
|
// IdSeries = request.IdSeries.Value
|
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
//if (!await historyService.CreateAsync(historyItem) || !await historyService.CommitAsync())
|
|
|
|
|
|
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при добавлении записи в историю" } }));
|
|
|
|
|
|
|
|
|
|
|
|
//var createdObj = await historyService.Get()
|
|
|
|
|
|
// .Include(t => t.Template)
|
|
|
|
|
|
// .Include(t => t.RobotHistoryLevel)
|
|
|
|
|
|
// .FirstOrDefaultAsync(t => t.Id == historyItem.Id);
|
|
|
|
|
|
|
|
|
|
|
|
//var response = mapper.Map<RobotTemplateHistoryResponse>(createdObj);
|
|
|
|
|
|
//var createdUri = uriService.GetAllUri(ApiRoutes.RobotTemplateHistory.GetAll) + $"?{nameof(RobotTemplateHistoryQuery.IdSeries)}={createdObj!.IdSeries}";
|
|
|
|
|
|
|
|
|
|
|
|
//return Created(createdUri, new Response<RobotTemplateHistoryResponse>(response, true));
|
|
|
|
|
|
|
|
|
|
|
|
return Ok("Доделать");
|
2023-10-04 15:22:06 +10:00
|
|
|
|
}
|
2023-10-04 13:41:33 +10:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|