feat(api): RobotHistory отображение пользователя

This commit is contained in:
Mikhail Trubnikov
2024-07-22 15:54:07 +10:00
parent 08b8fba8a5
commit b392a8dc7b

View File

@@ -28,6 +28,7 @@ namespace PARR.API.Controllers.V1
private readonly IRobotHistoryService robotHistoryService; private readonly IRobotHistoryService robotHistoryService;
private readonly IRobotConfigurationService robotConfigurationService; private readonly IRobotConfigurationService robotConfigurationService;
private readonly IClientService clientService; private readonly IClientService clientService;
private readonly IUserService userService;
public RobotHistoryController( public RobotHistoryController(
IValidator<RobotHistoryRequest> validator, IValidator<RobotHistoryRequest> validator,
@@ -35,7 +36,8 @@ namespace PARR.API.Controllers.V1
IUriService uriService, IUriService uriService,
IRobotHistoryService robotHistoryService, IRobotHistoryService robotHistoryService,
IRobotConfigurationService robotConfigurationService, IRobotConfigurationService robotConfigurationService,
IClientService clientService IClientService clientService,
IUserService userService
) )
{ {
this.validator = validator; this.validator = validator;
@@ -44,6 +46,7 @@ namespace PARR.API.Controllers.V1
this.robotHistoryService = robotHistoryService; this.robotHistoryService = robotHistoryService;
this.robotConfigurationService = robotConfigurationService; this.robotConfigurationService = robotConfigurationService;
this.clientService = clientService; this.clientService = clientService;
this.userService = userService;
} }
@@ -81,7 +84,14 @@ namespace PARR.API.Controllers.V1
if (!history.Any()) if (!history.Any())
return NoContent(); 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<List<RobotHistoryResponse>>(history); var response = mapper.Map<List<RobotHistoryResponse>>(history);
response.ForEach(item =>
{
item.User = mapper.Map<UserBaseResponse>(users.FirstOrDefault(t => t.Ip == item.RobotIp));
});
var paginationResponse = new PagedResponse<RobotHistoryResponse>(response, true).GetPaginatedProps(paginationFilter, query); var paginationResponse = new PagedResponse<RobotHistoryResponse>(response, true).GetPaginatedProps(paginationFilter, query);
return Ok(paginationResponse); return Ok(paginationResponse);
@@ -129,6 +139,7 @@ namespace PARR.API.Controllers.V1
.FirstOrDefaultAsync(t => t.Id == history.Id); .FirstOrDefaultAsync(t => t.Id == history.Id);
var response = mapper.Map<RobotHistoryResponse>(createdObj); var response = mapper.Map<RobotHistoryResponse>(createdObj);
response.User = mapper.Map<UserBaseResponse>(userService.Get().FirstOrDefaultAsync(t => t.Ip == response.RobotIp));
//todo: createdUri //todo: createdUri
//var createdUri = uriService.GetAllUri(ApiRoutes.RobotTemplateHistory.GetAll) + $"?{nameof(RobotTemplateHistoryQuery.IdSeries)}={createdObj!.IdSeries}"; //var createdUri = uriService.GetAllUri(ApiRoutes.RobotTemplateHistory.GetAll) + $"?{nameof(RobotTemplateHistoryQuery.IdSeries)}={createdObj!.IdSeries}";