feat(api): реализован GetAll UnitFieldValue по Id FieldValue

This commit is contained in:
Mikhail Kuznetsov
2025-09-22 11:04:27 +10:00
parent e094db168f
commit 8b0f173abe
7 changed files with 84 additions and 21 deletions

View File

@@ -431,13 +431,16 @@
public const string getParam = "{id}";
}
#region UnitField
public static class UnitField
{
public const string GetAll = Base + "/unit-fields/";
public const string Get = Base + "/unit-fields/" + getParam;
public const string GetAllValues = Base + "/unit-fields/" + getParam+"/values";
public const string getParam = "{id}";
}
#endregion
#region Расписание ЕСПП

View File

@@ -10,6 +10,6 @@
/// <summary>
/// Соответствующее полю значение
/// </summary>
public required ValueResponse Value { get; set; }
public required UnitFieldValueResponse Value { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace PARR.API.Contracts.V1.Responses
{
public class UnitFieldValueBaseResponse
{
public Guid Id { get; set; }
public string? Value { get; set; }
}
public class UnitFieldValueResponse : UnitFieldValueBaseResponse { }
}

View File

@@ -1,14 +0,0 @@
namespace PARR.API.Contracts.V1.Responses
{
public class ValueBaseResponse
{
public Guid Id { get; set; }
public string Value { get; set; }
}
public class ValueResponse : ValueBaseResponse
{
}
}

View File

@@ -5,12 +5,11 @@ using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1;
using PARR.API.Controllers.V1.Base;
using PARR.Constants;
using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.API.Controllers
namespace PARR.API.Controllers.V1
{
/// <summary>
/// Справочник полей

View File

@@ -0,0 +1,67 @@
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
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.Constants;
using PARR.DAL.DomainModels;
using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.API.Controllers.V1
{
/// <summary>
/// Управление значениями атрибутов
/// </summary>
[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;
}
/// <summary>
/// Список доступных значений аттрибутов
/// </summary>
/// <param name="paginationQuery"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.UnitField.GetAllValues)]
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromRoute] Guid id)
{
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
var query = unitFieldValueService.Get()
.Where(t => t.UnitInValues.Any(t => t.FieldId == id))
.OrderBy(t => t.Value);
var fieldValues = await unitFieldValueService.GetPage(query, paginationFilter).ToListAsync();
if (!fieldValues.Any())
return NoContent();
var fielsValuesResponse = mapper.Map<List<UnitFieldValueResponse>>(fieldValues);
var paginationResponse = new PagedResponse<UnitFieldValueResponse>(fielsValuesResponse, true).GetPaginatedProps(paginationFilter, query);
return Ok(paginationResponse);
}
}
}

View File

@@ -108,7 +108,7 @@ namespace PARR.API.MappingProfiles
CreateMap<UnitField, FieldResponse>()
.ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.DisplayName)) ? s.AihitName : s.DisplayName));
CreateMap<UnitFieldValue, ValueResponse>();
CreateMap<UnitFieldValue, UnitFieldValueResponse>();
CreateMap<UnitInValue, AttributeResponse>()
.ForMember(d => d.Field, o => o.MapFrom(s => s.Field))
@@ -353,9 +353,6 @@ namespace PARR.API.MappingProfiles
CreateMap<WeekendDay, WeekendResponse>();
CreateMap<UnitField, FieldResponse>()
.ForMember(d => d.Name, o => o.MapFrom(s => (s.DisplayName == null) ? s.AihitName : s.DisplayName));
#region TemplateHistory
CreateMap<TemplateHistory, TemplateHistoryResponse>()