Список хостов по маске. Список шаблонов по маске
This commit is contained in:
54
PARR.API/Controllers/V1/HostController.cs
Normal file
54
PARR.API/Controllers/V1/HostController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.BLL.Helpers;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class HostController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IHostService hostService;
|
||||
|
||||
public HostController(IMapper mapper, IHostService hostService)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.hostService = hostService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список хостов постранично
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Host.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] HostQuery request)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<DAL.Models.Host> query = hostService.Get().Include(s => s.EkStatus).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<HostResponse>>(hosts);
|
||||
var paginationResponse = new PagedResponse<HostResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.BLL.Helpers;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
@@ -40,8 +41,8 @@ namespace PARR.API.Controllers.V1
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<Template> query = templateService.GetWithIncludes()
|
||||
.OrderBy(t => t.Name)
|
||||
.AsSplitQuery();
|
||||
.OrderBy(t => t.Name)
|
||||
.AsSplitQuery();
|
||||
|
||||
if (filter.StatusCode.HasValue)
|
||||
{
|
||||
@@ -61,6 +62,9 @@ namespace PARR.API.Controllers.V1
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(filter.Mask))
|
||||
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(filter.Mask)));
|
||||
|
||||
var templates = await templateService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!templates.Any())
|
||||
|
||||
Reference in New Issue
Block a user