feat(api): Создан UnitFieldController для отображения списка атрибутов ЭК
This commit is contained in:
@@ -431,6 +431,14 @@
|
|||||||
public const string getParam = "{id}";
|
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 Расписание ЕСПП
|
#region Расписание ЕСПП
|
||||||
|
|
||||||
public static class EsppScheduleTypeSchedule
|
public static class EsppScheduleTypeSchedule
|
||||||
|
|||||||
71
PARR.API/Controllers/UnitFieldController.cs
Normal file
71
PARR.API/Controllers/UnitFieldController.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -353,6 +353,9 @@ namespace PARR.API.MappingProfiles
|
|||||||
|
|
||||||
CreateMap<WeekendDay, WeekendResponse>();
|
CreateMap<WeekendDay, WeekendResponse>();
|
||||||
|
|
||||||
|
CreateMap<UnitField, FieldResponse>()
|
||||||
|
.ForMember(d => d.Name, o => o.MapFrom(s => (s.DisplayName == null) ? s.AihitName : s.DisplayName));
|
||||||
|
|
||||||
#region TemplateHistory
|
#region TemplateHistory
|
||||||
|
|
||||||
CreateMap<TemplateHistory, TemplateHistoryResponse>()
|
CreateMap<TemplateHistory, TemplateHistoryResponse>()
|
||||||
|
|||||||
Reference in New Issue
Block a user