71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
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.Base;
|
|
using PARR.Constants;
|
|
using PARR.DAL.Services.Interfaces.Unit;
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
{
|
|
/// <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));
|
|
}
|
|
}
|
|
}
|