feta(api): unitFieldValue поиск по имени

This commit is contained in:
Mikhail Trubnikov
2025-11-24 14:21:04 +10:00
parent e6bf3a90fd
commit 57a9df18c0
4 changed files with 21 additions and 13 deletions

View File

@@ -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}";
}

View File

@@ -0,0 +1,10 @@
namespace PARR.API.Contracts.V1.Requests.Queries
{
public class UnitFieldValueQuery
{
/// <summary>
/// Маска значения (%коммутатор%)
/// </summary>
public string? Mask { get; set; }
}
}

View File

@@ -17,17 +17,14 @@ namespace PARR.API.Controllers.V1
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class UnitFieldController : BaseApiController
{
private readonly ILogger<JobController> logger;
private readonly IUnitFieldService unitFieldService;
private readonly IMapper mapper;
public UnitFieldController(
ILogger<JobController> logger,
IUnitFieldService unitFieldService,
IMapper mapper
)
{
this.logger = logger;
this.unitFieldService = unitFieldService;
this.mapper = mapper;
}

View File

@@ -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<TnkController> logger;
private readonly IMapper mapper;
private readonly IUnitFieldService unitFieldService;
private readonly IUnitFieldValueService unitFieldValueService;
public UnitFieldValueController(
ILogger<TnkController> 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
/// <param name="paginationQuery"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.UnitField.GetAllValues)]
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromRoute] Guid id)
public async Task<IActionResult> GetAll([FromRoute] Guid fieldId, [FromQuery] PaginationQuery paginationQuery, [FromQuery] UnitFieldValueQuery filter)
{
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
var query = unitFieldValueService.Get()
.Where(t => t.UnitInValues.Any(t => t.FieldId == id))
IQueryable<UnitFieldValue> 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())