feat(api): в HostResponse добавлена информация о компонентном составе

This commit is contained in:
Mikhail Trubnikov
2023-11-30 10:17:02 +10:00
parent 5cfa2a852f
commit 1222c102f0
7 changed files with 64 additions and 22 deletions

View File

@@ -5,5 +5,7 @@
public Guid Id { get; set; }
public required string Name { get; set; }
public ApplicationTypeResponse? Type { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace PARR.API.Contracts.V1.Responses
{
public class ApplicationTypeResponse
{
public Guid Id { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
namespace PARR.API.Contracts.V1.Responses
{
public class HostBaseResponse
{
public Guid Id { get; set; }
public string Ek { get; set; } = string.Empty;
public required string IP { get; set; }
public string? Status { get; set; }
public string? WorkGroup { get; set; }
public string? ResponseArea { get; set; }
}
/// <summary>
/// Респонс Хоста для Шаблона
/// </summary>
public class HostTemplateResponse : HostBaseResponse
{
}
/// <summary>
/// Респонс Хоста с приложениями (компнентном составе)
/// </summary>
public class HostWithApplicationsResponse : HostBaseResponse
{
public List<ApplicationResponse>? Applications { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
namespace PARR.API.Contracts.V1.Responses
{
public class HostResponse
{
public Guid Id { get; set; }
public string Ek { get; set; }
public required string IP { get; set; }
public string? Status { get; set; }
public string? WorkGroup { get; set; }
public string? ResponseArea { get; set; }
}
}

View File

@@ -22,7 +22,7 @@
public DateTimeOffset NextRun { get; set; }
public HostResponse? Host { get; set; }
public HostTemplateResponse? Host { get; set; }
public WorkResponse? Work { get; set; }
public ProcessResponse? Process { get; set; }

View File

@@ -38,6 +38,7 @@ namespace PARR.API.Controllers.V1
IQueryable<DAL.Models.Host> query = hostService.Get()
.Include(s => s.EkStatus)
.Include(s => s.ResponseArea)
.Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
.OrderBy(t => t.Ek);
if (!string.IsNullOrEmpty(request.Mask))
@@ -48,8 +49,8 @@ namespace PARR.API.Controllers.V1
if (!hosts.Any())
return NoContent();
var hostResponse = mapper.Map<List<HostResponse>>(hosts);
var paginationResponse = new PagedResponse<HostResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
var hostResponse = mapper.Map<List<HostWithApplicationsResponse>>(hosts);
var paginationResponse = new PagedResponse<HostWithApplicationsResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
return Ok(paginationResponse);
}

View File

@@ -49,12 +49,24 @@ namespace PARR.API.MappingProfiles
CreateMap<Work, WorkResponse>();
CreateMap<Application, ApplicationResponse>();
CreateMap<Application, ApplicationResponse>()
.ForMember(t => t.Type, o => o.MapFrom(s => s.ApplicationType));
CreateMap<DAL.Models.Host, HostResponse>()
CreateMap<ApplicationType, ApplicationTypeResponse>();
// --- Host ---
CreateMap<DAL.Models.Host, HostBaseResponse>()
.Include<DAL.Models.Host, HostTemplateResponse>()
.Include<DAL.Models.Host, HostWithApplicationsResponse>()
.ForMember(d => d.Status, o => o.MapFrom(s => s.EkStatus!.Name))
.ForMember(d => d.ResponseArea, o => o.MapFrom(s => s.ResponseArea!.Name));
CreateMap<DAL.Models.Host, HostTemplateResponse>();
CreateMap<DAL.Models.Host, HostWithApplicationsResponse>()
.ForMember(d => d.Applications, o => o.MapFrom(s => s.ApplicationsInHosts.Select(t => t.Application).OrderBy(t=>t.Name)));
// === Host ===
CreateMap<RobotStatus, RobotStatusResponse>();
CreateMap<RobotHistoryLevel, RobotHistoryLevelResponse>();