| | | 1 | | using FAU.Entidades; |
| | | 2 | | using FAU.Logica.Services; |
| | | 3 | | using Microsoft.AspNetCore.Authorization; |
| | | 4 | | using Microsoft.AspNetCore.Mvc; |
| | | 5 | | |
| | | 6 | | namespace FAU.API.Controllers; |
| | | 7 | | |
| | | 8 | | [ApiController] |
| | | 9 | | [Route("api/unidades/{unidadId}/sub-unidades")] |
| | | 10 | | [Authorize] |
| | | 11 | | public class SubUnidadesController : ControllerBase |
| | | 12 | | { |
| | | 13 | | private readonly ISubUnidadService _service; |
| | | 14 | | |
| | 4 | 15 | | public SubUnidadesController(ISubUnidadService service) => _service = service; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// GET /api/unidades/{unidadId}/sub-unidades |
| | | 19 | | /// Retorna las sub-unidades vigentes de una unidad. |
| | | 20 | | /// </summary> |
| | | 21 | | [HttpGet] |
| | | 22 | | [FAU.API.Security.RequirePermission(PermisoEnum.VerSubUnidades)] |
| | | 23 | | public async Task<IActionResult> GetSubUnidades(long unidadId) |
| | | 24 | | { |
| | 2 | 25 | | var items = await _service.GetByUnidadIdAsync(unidadId); |
| | 2 | 26 | | var list = items.ToList(); |
| | | 27 | | |
| | 2 | 28 | | if (!list.Any()) |
| | 1 | 29 | | return Ok(new { unidadId, subUnidades = Array.Empty<object>() }); |
| | | 30 | | |
| | 1 | 31 | | return Ok(new |
| | 1 | 32 | | { |
| | 1 | 33 | | unidadId, |
| | 0 | 34 | | subUnidades = list.Select(s => new |
| | 0 | 35 | | { |
| | 0 | 36 | | id = s.Id, |
| | 0 | 37 | | codigo = s.Codigo, |
| | 0 | 38 | | denominacion = s.Denominacion, |
| | 0 | 39 | | vigente = s.Vigente |
| | 0 | 40 | | }) |
| | 1 | 41 | | }); |
| | 2 | 42 | | } |
| | | 43 | | } |