diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs
index af2a32b6..18adeb96 100644
--- a/PARR.API/Contracts/V1/ApiRoutes.cs
+++ b/PARR.API/Contracts/V1/ApiRoutes.cs
@@ -445,7 +445,9 @@
{
public const string GetAll = Base + "/unit-fields/";
public const string Get = Base + "/unit-fields/" + getParam;
- public const string GetAllValues = Base + "/unit-fields/" + getParam + "/values";
+
+ // todo: этот маршрут нужно вынести в отдельны класс маршрутов
+ public const string GetAllValues = Base + "/unit-fields/" + "{fieldId}" + "/values";
public const string getParam = "{id}";
}
diff --git a/PARR.API/Contracts/V1/Requests/Queries/UnitFieldValueQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/UnitFieldValueQuery.cs
new file mode 100644
index 00000000..8d155450
--- /dev/null
+++ b/PARR.API/Contracts/V1/Requests/Queries/UnitFieldValueQuery.cs
@@ -0,0 +1,10 @@
+namespace PARR.API.Contracts.V1.Requests.Queries
+{
+ public class UnitFieldValueQuery
+ {
+ ///
+ /// Маска значения (%коммутатор%)
+ ///
+ public string? Mask { get; set; }
+ }
+}
diff --git a/PARR.API/Controllers/V1/UnitFieldController.cs b/PARR.API/Controllers/V1/UnitFieldController.cs
index d4ea99e9..2d22bf06 100644
--- a/PARR.API/Controllers/V1/UnitFieldController.cs
+++ b/PARR.API/Controllers/V1/UnitFieldController.cs
@@ -17,17 +17,14 @@ namespace PARR.API.Controllers.V1
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class UnitFieldController : BaseApiController
{
- private readonly ILogger logger;
private readonly IUnitFieldService unitFieldService;
private readonly IMapper mapper;
public UnitFieldController(
- ILogger logger,
IUnitFieldService unitFieldService,
IMapper mapper
)
{
- this.logger = logger;
this.unitFieldService = unitFieldService;
this.mapper = mapper;
}
diff --git a/PARR.API/Controllers/V1/UnitFieldValueController.cs b/PARR.API/Controllers/V1/UnitFieldValueController.cs
index 387b9269..be4bef4e 100644
--- a/PARR.API/Controllers/V1/UnitFieldValueController.cs
+++ b/PARR.API/Controllers/V1/UnitFieldValueController.cs
@@ -8,8 +8,10 @@ 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.Constants;
using PARR.DAL.DomainModels;
+using PARR.DAL.Models.Unit;
using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.API.Controllers.V1
@@ -20,21 +22,15 @@ namespace PARR.API.Controllers.V1
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class UnitFieldValueController : BaseApiController
{
- private readonly ILogger logger;
private readonly IMapper mapper;
- private readonly IUnitFieldService unitFieldService;
private readonly IUnitFieldValueService unitFieldValueService;
public UnitFieldValueController(
- ILogger logger,
IMapper mapper,
- IUnitFieldService unitFieldService,
IUnitFieldValueService unitFieldValueService
)
{
- this.logger = logger;
this.mapper = mapper;
- this.unitFieldService = unitFieldService;
this.unitFieldValueService = unitFieldValueService;
}
@@ -44,14 +40,17 @@ namespace PARR.API.Controllers.V1
///
///
[HttpGet(ApiRoutes.UnitField.GetAllValues)]
- public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromRoute] Guid id)
+ public async Task GetAll([FromRoute] Guid fieldId, [FromQuery] PaginationQuery paginationQuery, [FromQuery] UnitFieldValueQuery filter)
{
var paginationFilter = mapper.Map(paginationQuery);
- var query = unitFieldValueService.Get()
- .Where(t => t.UnitInValues.Any(t => t.FieldId == id))
+ IQueryable query = unitFieldValueService.Get()
+ .Where(t => t.UnitInValues.Any(t => t.FieldId == fieldId))
.OrderBy(t => t.Value);
+ if (!string.IsNullOrEmpty(filter.Mask))
+ query = query.Where(t => EF.Functions.Like(t.Value!.ToLower(), SqlHelpers.RegexToLike(filter.Mask)));
+
var fieldValues = await unitFieldValueService.GetPage(query, paginationFilter).ToListAsync();
if (!fieldValues.Any())