From b392a8dc7b51c6acd23e3ebdc09a4d48bc0ee6c5 Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Mon, 22 Jul 2024 15:54:07 +1000 Subject: [PATCH] =?UTF-8?q?feat(api):=20RobotHistory=20=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PARR.API/Controllers/V1/RobotHistoryController.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/PARR.API/Controllers/V1/RobotHistoryController.cs b/PARR.API/Controllers/V1/RobotHistoryController.cs index 500a4f87..0a8c5959 100644 --- a/PARR.API/Controllers/V1/RobotHistoryController.cs +++ b/PARR.API/Controllers/V1/RobotHistoryController.cs @@ -28,6 +28,7 @@ namespace PARR.API.Controllers.V1 private readonly IRobotHistoryService robotHistoryService; private readonly IRobotConfigurationService robotConfigurationService; private readonly IClientService clientService; + private readonly IUserService userService; public RobotHistoryController( IValidator validator, @@ -35,7 +36,8 @@ namespace PARR.API.Controllers.V1 IUriService uriService, IRobotHistoryService robotHistoryService, IRobotConfigurationService robotConfigurationService, - IClientService clientService + IClientService clientService, + IUserService userService ) { this.validator = validator; @@ -44,6 +46,7 @@ namespace PARR.API.Controllers.V1 this.robotHistoryService = robotHistoryService; this.robotConfigurationService = robotConfigurationService; this.clientService = clientService; + this.userService = userService; } @@ -81,7 +84,14 @@ namespace PARR.API.Controllers.V1 if (!history.Any()) return NoContent(); + var robotsIp = history.Where(t => !string.IsNullOrEmpty(t.RobotIp)).Select(t => t.RobotIp).Distinct().ToList(); + var users = await userService.Get().Where(t => robotsIp.Any(x => x == t.Ip)).Distinct().ToListAsync(); + var response = mapper.Map>(history); + response.ForEach(item => + { + item.User = mapper.Map(users.FirstOrDefault(t => t.Ip == item.RobotIp)); + }); var paginationResponse = new PagedResponse(response, true).GetPaginatedProps(paginationFilter, query); return Ok(paginationResponse); @@ -129,6 +139,7 @@ namespace PARR.API.Controllers.V1 .FirstOrDefaultAsync(t => t.Id == history.Id); var response = mapper.Map(createdObj); + response.User = mapper.Map(userService.Get().FirstOrDefaultAsync(t => t.Ip == response.RobotIp)); //todo: createdUri //var createdUri = uriService.GetAllUri(ApiRoutes.RobotTemplateHistory.GetAll) + $"?{nameof(RobotTemplateHistoryQuery.IdSeries)}={createdObj!.IdSeries}";