diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs
index bf7af6ea..9b1591f7 100644
--- a/PARR.API/Contracts/V1/ApiRoutes.cs
+++ b/PARR.API/Contracts/V1/ApiRoutes.cs
@@ -73,6 +73,10 @@
public const string Create = Base + "/generator-templates/";
}
+ public static class Host
+ {
+ public const string GetAll = Base + "/hosts/";
+ }
//public static class Layer
//{
diff --git a/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
new file mode 100644
index 00000000..364595f4
--- /dev/null
+++ b/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
@@ -0,0 +1,10 @@
+namespace PARR.API.Contracts.V1.Requests.Queries
+{
+ public class HostQuery
+ {
+ ///
+ /// Поиск по маске ЭК. Например: "*-ДВС"
+ ///
+ public string? Mask { get; set; }
+ }
+}
diff --git a/PARR.API/Contracts/V1/Requests/Queries/TemplateQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/TemplateQuery.cs
index 86b7ebde..4f1b583e 100644
--- a/PARR.API/Contracts/V1/Requests/Queries/TemplateQuery.cs
+++ b/PARR.API/Contracts/V1/Requests/Queries/TemplateQuery.cs
@@ -6,5 +6,10 @@
/// Статус шаблона: 10, 20, 30
///
public int? StatusCode { get; set; }
+
+ ///
+ /// Поиск по маске. Например: "*-ДВС"
+ ///
+ public string? Mask { get; set; }
}
}
diff --git a/PARR.API/Controllers/V1/HostController.cs b/PARR.API/Controllers/V1/HostController.cs
new file mode 100644
index 00000000..0abde1ab
--- /dev/null
+++ b/PARR.API/Controllers/V1/HostController.cs
@@ -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;
+ }
+
+
+ ///
+ /// Получить список хостов постранично
+ ///
+ ///
+ ///
+ [HttpGet(ApiRoutes.Host.GetAll)]
+ public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] HostQuery request)
+ {
+ var paginationFilter = mapper.Map(paginationQuery);
+
+ IQueryable 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>(hosts);
+ var paginationResponse = new PagedResponse(hostResponse, true).GetPaginatedProps(paginationFilter, query);
+
+ return Ok(paginationResponse);
+ }
+ }
+}
diff --git a/PARR.API/Controllers/V1/TemplateController.cs b/PARR.API/Controllers/V1/TemplateController.cs
index 39d6ee79..f45713f8 100644
--- a/PARR.API/Controllers/V1/TemplateController.cs
+++ b/PARR.API/Controllers/V1/TemplateController.cs
@@ -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(paginationQuery);
IQueryable 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())