feat(api): HostController вывод даных из таблицы Unit
This commit is contained in:
@@ -11,7 +11,9 @@ using PARR.API.Extensions;
|
||||
using PARR.BLL.Helpers;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models.Unit;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
@@ -20,11 +22,17 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
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.hostService = hostService;
|
||||
this.unitService = unitService;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,23 +46,42 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<DAL.Models.Host> query = hostService.Get()
|
||||
.Include(t=>t.WorkGroup).ThenInclude(t=>t!.ResponseArea)
|
||||
.Include(s => s.EkStatus)
|
||||
.Include(s => s.ResponseArea)
|
||||
.Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
.OrderBy(t => t.Ek);
|
||||
//IQueryable<DAL.Models.Host> query = hostService.Get()
|
||||
// .Include(t=>t.WorkGroup).ThenInclude(t=>t!.ResponseArea)
|
||||
// .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))
|
||||
// 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))
|
||||
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();
|
||||
|
||||
var hostResponse = mapper.Map<List<HostWithApplicationsResponse>>(hosts);
|
||||
var paginationResponse = new PagedResponse<HostWithApplicationsResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
var unitResponse = mapper.Map<List<UnitWithAttributesResponse>>(units);
|
||||
var paginationResponse = new PagedResponse<UnitWithAttributesResponse>(unitResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
@@ -68,19 +95,31 @@ namespace PARR.API.Controllers.V1
|
||||
[HttpGet(ApiRoutes.Host.Get)]
|
||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||
{
|
||||
var host = await hostService.Get()
|
||||
.Include(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
|
||||
.Include(s => s.EkStatus)
|
||||
.Include(s => s.ResponseArea)
|
||||
.Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
//var host = await hostService.Get()
|
||||
// .Include(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
|
||||
// .Include(s => s.EkStatus)
|
||||
// .Include(s => s.ResponseArea)
|
||||
// .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
// .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();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user