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}";