From 691a256d9c068d7471b68bfdfb2a5a9d8111b0ec Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Thu, 11 Sep 2025 17:18:04 +1000 Subject: [PATCH] =?UTF-8?q?feat(api):=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=20UnitFieldController=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B0=D1=82=D1=80=D0=B8?= =?UTF-8?q?=D0=B1=D1=83=D1=82=D0=BE=D0=B2=20=D0=AD=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PARR.API/Contracts/V1/ApiRoutes.cs | 8 +++ PARR.API/Controllers/UnitFieldController.cs | 71 +++++++++++++++++++ .../DomainToResponseProfile.cs | 3 + 3 files changed, 82 insertions(+) create mode 100644 PARR.API/Controllers/UnitFieldController.cs diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs index fff342c1..0696bbcf 100644 --- a/PARR.API/Contracts/V1/ApiRoutes.cs +++ b/PARR.API/Contracts/V1/ApiRoutes.cs @@ -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 diff --git a/PARR.API/Controllers/UnitFieldController.cs b/PARR.API/Controllers/UnitFieldController.cs new file mode 100644 index 00000000..0e078d5d --- /dev/null +++ b/PARR.API/Controllers/UnitFieldController.cs @@ -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 +{ + /// + /// Справочник полей + /// + [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; + } + + /// + /// Список доступных в БД атрибутов ЭК + /// + /// + [HttpGet(ApiRoutes.UnitField.GetAll)] + public async Task GetAll() + { + var unitFields = await unitFieldService.Get().OrderBy(t => t.DisplayName) + .ToListAsync(); + + if (!unitFields.Any()) + return NoContent(); + + var response = mapper.Map>(unitFields); + + return Ok(new Response>(response, true)); + } + + /// + /// Получить имя атрибута по Id + /// + /// + [HttpGet(ApiRoutes.UnitField.Get)] + public async Task Get([FromRoute] Guid id) + { + var unitField = await unitFieldService.Get().FirstOrDefaultAsync(t => t.Id == id); + + if (unitField == null) + return NoContent(); + + var response = mapper.Map(unitField); + + return Ok(new Response(response, true)); + } + } +} diff --git a/PARR.API/MappingProfiles/DomainToResponseProfile.cs b/PARR.API/MappingProfiles/DomainToResponseProfile.cs index de56b81f..459207e9 100644 --- a/PARR.API/MappingProfiles/DomainToResponseProfile.cs +++ b/PARR.API/MappingProfiles/DomainToResponseProfile.cs @@ -353,6 +353,9 @@ namespace PARR.API.MappingProfiles CreateMap(); + CreateMap() + .ForMember(d => d.Name, o => o.MapFrom(s => (s.DisplayName == null) ? s.AihitName : s.DisplayName)); + #region TemplateHistory CreateMap()