feat(api): Создан UnitFieldController для отображения списка атрибутов ЭК

This commit is contained in:
Mikhail Kuznetsov
2025-09-11 17:18:04 +10:00
parent 14519a843d
commit 691a256d9c
3 changed files with 82 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,71 @@
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
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
{
/// <summary>
/// Справочник полей
/// </summary>
[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;
}
/// <summary>
/// Список доступных в БД атрибутов ЭК
/// </summary>
/// <returns></returns>
[HttpGet(ApiRoutes.UnitField.GetAll)]
public async Task<IActionResult> GetAll()
{
var unitFields = await unitFieldService.Get().OrderBy(t => t.DisplayName)
.ToListAsync();
if (!unitFields.Any())
return NoContent();
var response = mapper.Map<List<FieldResponse>>(unitFields);
return Ok(new Response<List<FieldResponse>>(response, true));
}
/// <summary>
/// Получить имя атрибута по Id
/// </summary>
/// <returns></returns>
[HttpGet(ApiRoutes.UnitField.Get)]
public async Task<IActionResult> Get([FromRoute] Guid id)
{
var unitField = await unitFieldService.Get().FirstOrDefaultAsync(t => t.Id == id);
if (unitField == null)
return NoContent();
var response = mapper.Map<FieldResponse>(unitField);
return Ok(new Response<FieldResponse>(response, true));
}
}
}

View File

@@ -353,6 +353,9 @@ 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>()