feat(api): HostController вывод даных из таблицы Unit
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
public class HostQuery
|
public class HostQuery
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поиск по маске ЭК. Например: "*-ДВС"
|
/// Поиск по маске ЭК. Например: "ВРТ-*-ДВС"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Mask { get; set; }
|
public string? Mask { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
17
PARR.API/Contracts/V1/Responses/AttributeResponse.cs
Normal file
17
PARR.API/Contracts/V1/Responses/AttributeResponse.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses
|
||||||
|
{
|
||||||
|
public class AttributeResponse
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Имя из поля DisplayName, если пустое - берём AihitName
|
||||||
|
/// </summary>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Соответствующее полю значение
|
||||||
|
/// </summary>
|
||||||
|
public required string Value { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
PARR.API/Contracts/V1/Responses/UnitResponse.cs
Normal file
18
PARR.API/Contracts/V1/Responses/UnitResponse.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses
|
||||||
|
{
|
||||||
|
public class UnitResponse
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Response с всеми аттребутами и их значениями
|
||||||
|
/// </summary>
|
||||||
|
public class UnitWithAttributesResponse : UnitResponse
|
||||||
|
{
|
||||||
|
public List<AttributeResponse>? Attributes { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,9 @@ using PARR.API.Extensions;
|
|||||||
using PARR.BLL.Helpers;
|
using PARR.BLL.Helpers;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
|
using PARR.DAL.Models.Unit;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
using PARR.DAL.Services.Interfaces.Unit;
|
||||||
|
|
||||||
namespace PARR.API.Controllers.V1
|
namespace PARR.API.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -20,11 +22,17 @@ namespace PARR.API.Controllers.V1
|
|||||||
{
|
{
|
||||||
private readonly IMapper mapper;
|
private readonly IMapper mapper;
|
||||||
private readonly IHostService hostService;
|
private readonly IHostService hostService;
|
||||||
|
private readonly IUnitService unitService;
|
||||||
|
|
||||||
public HostController(IMapper mapper, IHostService hostService)
|
public HostController(
|
||||||
|
IMapper mapper,
|
||||||
|
IHostService hostService,
|
||||||
|
IUnitService unitService
|
||||||
|
)
|
||||||
{
|
{
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.hostService = hostService;
|
this.hostService = hostService;
|
||||||
|
this.unitService = unitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,23 +46,42 @@ namespace PARR.API.Controllers.V1
|
|||||||
{
|
{
|
||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
IQueryable<DAL.Models.Host> query = hostService.Get()
|
//IQueryable<DAL.Models.Host> query = hostService.Get()
|
||||||
.Include(t=>t.WorkGroup).ThenInclude(t=>t!.ResponseArea)
|
// .Include(t=>t.WorkGroup).ThenInclude(t=>t!.ResponseArea)
|
||||||
.Include(s => s.EkStatus)
|
// .Include(s => s.EkStatus)
|
||||||
.Include(s => s.ResponseArea)
|
// .Include(s => s.ResponseArea)
|
||||||
.Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
// .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||||
.OrderBy(t => t.Ek);
|
// .OrderBy(t => t.Ek);
|
||||||
|
|
||||||
|
//if (!string.IsNullOrEmpty(request.Mask))
|
||||||
|
// query = query.Where(t => EF.Functions.Like(t.Ek.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
|
||||||
|
|
||||||
|
//var hosts = await hostService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
|
//if (!hosts.Any())
|
||||||
|
// return NoContent();
|
||||||
|
|
||||||
|
//var hostResponse = mapper.Map<List<HostWithApplicationsResponse>>(hosts);
|
||||||
|
//var paginationResponse = new PagedResponse<HostWithApplicationsResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||||
|
|
||||||
|
IQueryable<Unit> query = unitService.Get()
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(t => t.UnitValues)
|
||||||
|
.ThenInclude(uv => uv.Value)
|
||||||
|
.Include(tf => tf.UnitValues)
|
||||||
|
.ThenInclude(uv => uv.Field)
|
||||||
|
.OrderBy(t => t.Name);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.Mask))
|
if (!string.IsNullOrEmpty(request.Mask))
|
||||||
query = query.Where(t => EF.Functions.Like(t.Ek.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
|
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
|
||||||
|
|
||||||
var hosts = await hostService.GetPage(query, paginationFilter).ToListAsync();
|
var units = await unitService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!hosts.Any())
|
if (!units.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
var hostResponse = mapper.Map<List<HostWithApplicationsResponse>>(hosts);
|
var unitResponse = mapper.Map<List<UnitWithAttributesResponse>>(units);
|
||||||
var paginationResponse = new PagedResponse<HostWithApplicationsResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
|
var paginationResponse = new PagedResponse<UnitWithAttributesResponse>(unitResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||||
|
|
||||||
return Ok(paginationResponse);
|
return Ok(paginationResponse);
|
||||||
}
|
}
|
||||||
@@ -68,19 +95,31 @@ namespace PARR.API.Controllers.V1
|
|||||||
[HttpGet(ApiRoutes.Host.Get)]
|
[HttpGet(ApiRoutes.Host.Get)]
|
||||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||||
{
|
{
|
||||||
var host = await hostService.Get()
|
//var host = await hostService.Get()
|
||||||
.Include(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
|
// .Include(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
|
||||||
.Include(s => s.EkStatus)
|
// .Include(s => s.EkStatus)
|
||||||
.Include(s => s.ResponseArea)
|
// .Include(s => s.ResponseArea)
|
||||||
.Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
// .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||||
.FirstOrDefaultAsync(t => t.Id == id);
|
// .FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
if (host == null)
|
//if (host == null)
|
||||||
|
// return NotFound();
|
||||||
|
|
||||||
|
//var response = mapper.Map<HostWithApplicationsResponse>(host);
|
||||||
|
|
||||||
|
var unit = await unitService.Get()
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(t => t.UnitValues)
|
||||||
|
.ThenInclude(uv => uv.Value)
|
||||||
|
.Include(tf => tf.UnitValues)
|
||||||
|
.ThenInclude(uv => uv.Field)
|
||||||
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
if (unit == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var response = mapper.Map<HostWithApplicationsResponse>(host);
|
var response = mapper.Map<UnitWithAttributesResponse>(unit);
|
||||||
|
|
||||||
return Ok(new Response<HostWithApplicationsResponse>(response, true));
|
return Ok(new Response<UnitWithAttributesResponse>(response, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using PARR.Constants.Shortcodes;
|
|||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
using PARR.DAL.Extensions;
|
using PARR.DAL.Extensions;
|
||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Models.Unit;
|
||||||
|
|
||||||
namespace PARR.API.MappingProfiles
|
namespace PARR.API.MappingProfiles
|
||||||
{
|
{
|
||||||
@@ -103,6 +104,21 @@ namespace PARR.API.MappingProfiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Unit
|
||||||
|
|
||||||
|
CreateMap<UnitInValue, AttributeResponse>()
|
||||||
|
.ForMember(d => d.Id, o => o.MapFrom(s => s.Value!.Id))
|
||||||
|
.ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.Field!.DisplayName)) ? s.Field!.AihitName : s.Field!.DisplayName))
|
||||||
|
.ForMember(d => d.Value, o => o.MapFrom(s => s.Value!.Value));
|
||||||
|
|
||||||
|
CreateMap<Unit, UnitResponse>()
|
||||||
|
.Include<Unit, UnitWithAttributesResponse>()
|
||||||
|
.ForMember(d => d.Name, o => o.MapFrom(s => s.Name));
|
||||||
|
|
||||||
|
CreateMap<Unit, UnitWithAttributesResponse>()
|
||||||
|
.ForMember(d => d.Attributes, o => o.MapFrom(s => s.UnitValues!.OrderBy(s => (string.IsNullOrEmpty(s.Field!.DisplayName)) ? s.Field!.AihitName : s.Field!.DisplayName)));
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region WorkGroup
|
#region WorkGroup
|
||||||
|
|
||||||
CreateMap<WorkGroup, WorkGroupResponse>();
|
CreateMap<WorkGroup, WorkGroupResponse>();
|
||||||
|
|||||||
Reference in New Issue
Block a user