feat(api): Создан UnitFieldController для отображения списка атрибутов ЭК
This commit is contained in:
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user