From 3f3ab424bae838564e68cddb1fce9513b7620089 Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Fri, 13 Oct 2023 15:28:17 +1000 Subject: [PATCH] =?UTF-8?q?feat(api):=20=D0=9F=D1=80=D0=BE=D1=81=D0=BC?= =?UTF-8?q?=D0=BE=D1=82=D1=80=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= =?UTF-8?q?=20=D1=80=D0=BE=D0=B1=D0=BE=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PARR.API/Contracts/V1/ApiRoutes.cs | 2 +- .../V1/Requests/Queries/RobotHistoryQuery.cs | 23 ++++++++ .../Queries/RobotTemplateHistoryQuery.cs | 15 ----- .../V1/Responses/RobotHistoryResponse.cs | 10 +++- .../Controllers/V1/RobotHistoryController.cs | 59 +++++++++++-------- .../DomainToResponseProfile.cs | 5 +- 6 files changed, 71 insertions(+), 43 deletions(-) create mode 100644 PARR.API/Contracts/V1/Requests/Queries/RobotHistoryQuery.cs delete mode 100644 PARR.API/Contracts/V1/Requests/Queries/RobotTemplateHistoryQuery.cs diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs index a142816c..aef688e4 100644 --- a/PARR.API/Contracts/V1/ApiRoutes.cs +++ b/PARR.API/Contracts/V1/ApiRoutes.cs @@ -75,7 +75,7 @@ public static class RobotHistory { - //public const string GetAll = Base + "/robot-histories/"; + public const string GetAll = Base + "/robot-histories/"; public const string Create = Base + "/robot-histories/"; } diff --git a/PARR.API/Contracts/V1/Requests/Queries/RobotHistoryQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/RobotHistoryQuery.cs new file mode 100644 index 00000000..9c060738 --- /dev/null +++ b/PARR.API/Contracts/V1/Requests/Queries/RobotHistoryQuery.cs @@ -0,0 +1,23 @@ +using PARR.DAL.Contracts; + +namespace PARR.API.Contracts.V1.Requests.Queries +{ + public class RobotHistoryQuery + { + /// + /// Фильтр по ИД шаблона + /// + public Guid? TemplateId { get; set; } + + /// + /// Фильтр по ИД робота + /// + public RobotsEnum? RobotCode { get; set; } + + /// + /// Фильтр по уровню истории + /// + public RobotHistoryLevelEnum? HistoryLevel { get; set; } + + } +} diff --git a/PARR.API/Contracts/V1/Requests/Queries/RobotTemplateHistoryQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/RobotTemplateHistoryQuery.cs deleted file mode 100644 index 9e29df48..00000000 --- a/PARR.API/Contracts/V1/Requests/Queries/RobotTemplateHistoryQuery.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace PARR.API.Contracts.V1.Requests.Queries -{ - public class RobotTemplateHistoryQuery - { - /// - /// Фильтр по ИД шаблона - /// - public Guid? TemplateId { get; set; } - - /// - /// Фильтр по ИД серии - /// - public Guid? IdSeries { get; set; } - } -} diff --git a/PARR.API/Contracts/V1/Responses/RobotHistoryResponse.cs b/PARR.API/Contracts/V1/Responses/RobotHistoryResponse.cs index c2930742..8e5ec1b1 100644 --- a/PARR.API/Contracts/V1/Responses/RobotHistoryResponse.cs +++ b/PARR.API/Contracts/V1/Responses/RobotHistoryResponse.cs @@ -10,11 +10,19 @@ public string? EsppMessage { get; set; } - public int TaskStatusCode { get; set; } + //public int TaskStatusCode { get; set; } + + public TaskStatusResponse? TaskStatus { get; set; } public Guid TaskId { get; set; } public RobotHistoryLevelResponse? Level { get; set; } + public Guid TemplateId { get; set; } + + public string? TemplateName { get; set; } + + + } } diff --git a/PARR.API/Controllers/V1/RobotHistoryController.cs b/PARR.API/Controllers/V1/RobotHistoryController.cs index 4516c988..cd6ca33a 100644 --- a/PARR.API/Controllers/V1/RobotHistoryController.cs +++ b/PARR.API/Controllers/V1/RobotHistoryController.cs @@ -4,10 +4,13 @@ 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; using PARR.API.Controllers.V1.Base; +using PARR.API.Extensions; using PARR.API.Services.Interfaces; +using PARR.DAL.DomainModels; using PARR.DAL.Models; using PARR.DAL.Services.Interfaces; @@ -38,39 +41,43 @@ namespace PARR.API.Controllers.V1 } - ///// - ///// Получить историю робота шаблонов - ///// - ///// - ///// - ///// - //[HttpGet(ApiRoutes.RobotTemplateHistory.GetAll)] - //public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] RobotTemplateHistoryQuery filter) - //{ - // var paginationFilter = mapper.Map(paginationQuery); + /// + /// Просмотр истории работы робота + /// + /// + /// + /// + [HttpGet(ApiRoutes.RobotHistory.GetAll)] + public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] RobotHistoryQuery request) + { + var paginationFilter = mapper.Map(paginationQuery); - // IQueryable query = historyService.Get() - // .Include(t => t.Template) - // .Include(t => t.RobotHistoryLevel) - // .OrderByDescending(t => t.DateCreated).ThenBy(t => t.IdSeries); + IQueryable query = robotHistoryService.Get() + .Include(t => t.RobotConfiguration) + .ThenInclude(t=>t!.Template) + .Include(t => t.RobotHistoryLevel) + .Include(t => t.StatusTask) + .OrderByDescending(t => t.DateCreated); - // if (filter.IdSeries != null) - // query = query.Where(t => t.IdSeries == filter.IdSeries); + if (request.TemplateId.HasValue) + query = query.Where(t => t.RobotConfiguration!.TemplateId == request.TemplateId.Value); - // if (filter.TemplateId != null) - // query = query.Where(t => t.TemplateId == filter.TemplateId); + if (request.RobotCode.HasValue) + query = query.Where(t => t.RobotConfiguration!.RobotCode == (int)request.RobotCode); + if (request.HistoryLevel.HasValue) + query = query.Where(t => t.HistoryLevel == (int)request.HistoryLevel); - // var history = await historyService.GetPage(query, paginationFilter).ToListAsync(); + var history = await robotHistoryService.GetPage(query, paginationFilter).ToListAsync(); - // if (!history.Any()) - // return NoContent(); + if (!history.Any()) + return NoContent(); - // var response = mapper.Map>(history); - // var paginationResponse = new PagedResponse(response, true).GetPaginatedProps(paginationFilter, query); + var response = mapper.Map>(history); + var paginationResponse = new PagedResponse(response, true).GetPaginatedProps(paginationFilter, query); - // return Ok(paginationResponse); - //} + return Ok(paginationResponse); + } /// @@ -105,7 +112,9 @@ namespace PARR.API.Controllers.V1 var createdObj = await robotHistoryService.Get() .Include(t => t.RobotConfiguration) + .ThenInclude(t => t!.Template) .Include(t => t.RobotHistoryLevel) + .Include(t => t.StatusTask) .FirstOrDefaultAsync(t => t.Id == history.Id); var response = mapper.Map(createdObj); diff --git a/PARR.API/MappingProfiles/DomainToResponseProfile.cs b/PARR.API/MappingProfiles/DomainToResponseProfile.cs index 02cb8700..ad16fe0a 100644 --- a/PARR.API/MappingProfiles/DomainToResponseProfile.cs +++ b/PARR.API/MappingProfiles/DomainToResponseProfile.cs @@ -71,7 +71,10 @@ namespace PARR.API.MappingProfiles CreateMap() .ForMember(d => d.Level, o => o.MapFrom(s => s.RobotHistoryLevel)) .ForMember(d => d.Date, o => o.MapFrom(s => s.DateCreated)) - .ForMember(d => d.TaskId, o => o.MapFrom(s => s.RobotConfigurationId)); + .ForMember(d => d.TaskId, o => o.MapFrom(s => s.RobotConfigurationId)) + .ForMember(d => d.TaskStatus, o => o.MapFrom(s => s.StatusTask)) + .ForMember(d => d.TemplateId, o => o.MapFrom(s => s.RobotConfiguration!.TemplateId)) + .ForMember(d => d.TemplateName, o => o.MapFrom(s => s.RobotConfiguration!.Template!.Name)); // --- RobotConfiguration ---