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 { /// /// Справочник полей /// [Authorize(Roles = ParrRoles.Administrator.Role)] public class UnitFieldController : BaseApiController { private readonly IUnitFieldService unitFieldService; private readonly IMapper mapper; public UnitFieldController( IUnitFieldService unitFieldService, IMapper mapper ) { this.unitFieldService = unitFieldService; this.mapper = mapper; } /// /// Список доступных в БД атрибутов ЭК /// /// [HttpGet(ApiRoutes.UnitField.GetAll)] public async Task GetAll() { var unitFields = await unitFieldService.Get() .OrderBy(t => t.AihitName) .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)); } } }