feat(api): RobotHistory отображение пользователя
This commit is contained in:
@@ -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<RobotHistoryRequest> 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<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);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
@@ -129,6 +139,7 @@ namespace PARR.API.Controllers.V1
|
||||
.FirstOrDefaultAsync(t => t.Id == history.Id);
|
||||
|
||||
var response = mapper.Map<RobotHistoryResponse>(createdObj);
|
||||
response.User = mapper.Map<UserBaseResponse>(userService.Get().FirstOrDefaultAsync(t => t.Ip == response.RobotIp));
|
||||
|
||||
//todo: createdUri
|
||||
//var createdUri = uriService.GetAllUri(ApiRoutes.RobotTemplateHistory.GetAll) + $"?{nameof(RobotTemplateHistoryQuery.IdSeries)}={createdObj!.IdSeries}";
|
||||
|
||||
Reference in New Issue
Block a user