Список хостов по маске. Список шаблонов по маске
This commit is contained in:
@@ -73,6 +73,10 @@
|
|||||||
public const string Create = Base + "/generator-templates/";
|
public const string Create = Base + "/generator-templates/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Host
|
||||||
|
{
|
||||||
|
public const string GetAll = Base + "/hosts/";
|
||||||
|
}
|
||||||
|
|
||||||
//public static class Layer
|
//public static class Layer
|
||||||
//{
|
//{
|
||||||
|
|||||||
10
PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
Normal file
10
PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||||
|
{
|
||||||
|
public class HostQuery
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск по маске ЭК. Например: "*-ДВС"
|
||||||
|
/// </summary>
|
||||||
|
public string? Mask { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,5 +6,10 @@
|
|||||||
/// Статус шаблона: 10, 20, 30
|
/// Статус шаблона: 10, 20, 30
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? StatusCode { get; set; }
|
public int? StatusCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск по маске. Например: "*-ДВС"
|
||||||
|
/// </summary>
|
||||||
|
public string? Mask { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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.Contracts.V1.Responses.Base;
|
||||||
using PARR.API.Controllers.V1.Base;
|
using PARR.API.Controllers.V1.Base;
|
||||||
using PARR.API.Extensions;
|
using PARR.API.Extensions;
|
||||||
|
using PARR.BLL.Helpers;
|
||||||
using PARR.DAL.Contracts;
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
@@ -40,8 +41,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
IQueryable<Template> query = templateService.GetWithIncludes()
|
IQueryable<Template> query = templateService.GetWithIncludes()
|
||||||
.OrderBy(t => t.Name)
|
.OrderBy(t => t.Name)
|
||||||
.AsSplitQuery();
|
.AsSplitQuery();
|
||||||
|
|
||||||
if (filter.StatusCode.HasValue)
|
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();
|
var templates = await templateService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!templates.Any())
|
if (!templates.Any())
|
||||||
|
|||||||
Reference in New Issue
Block a user