| | | 1 | | using FAU.Logica.DTOs; |
| | | 2 | | using FAU.Logica.Services; |
| | | 3 | | using Microsoft.AspNetCore.Authorization; |
| | | 4 | | using Microsoft.AspNetCore.Http; |
| | | 5 | | using Microsoft.AspNetCore.Mvc; |
| | | 6 | | |
| | | 7 | | namespace FAU.API.Controllers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Catálogo de motivos de baja |
| | | 11 | | /// </summary> |
| | | 12 | | [ApiController] |
| | | 13 | | [Route("api/motivos-baja")] |
| | | 14 | | [Authorize] |
| | | 15 | | [Produces("application/json")] |
| | | 16 | | public class MotivoBajaController : ControllerBase |
| | | 17 | | { |
| | | 18 | | private readonly IMotivoBajaService _motivoBajaService; |
| | | 19 | | private readonly ILogger<MotivoBajaController> _logger; |
| | | 20 | | |
| | 3 | 21 | | public MotivoBajaController( |
| | 3 | 22 | | IMotivoBajaService motivoBajaService, |
| | 3 | 23 | | ILogger<MotivoBajaController> logger) |
| | | 24 | | { |
| | 3 | 25 | | _motivoBajaService = motivoBajaService; |
| | 3 | 26 | | _logger = logger; |
| | 3 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Listar todos los motivos de baja vigentes |
| | | 31 | | /// GET /api/motivos-baja |
| | | 32 | | /// </summary> |
| | | 33 | | [HttpGet] |
| | | 34 | | [ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)] |
| | | 35 | | [ProducesResponseType(typeof(ApiResponse<string>), StatusCodes.Status500InternalServerError)] |
| | | 36 | | public async Task<IActionResult> GetMotivosBaja() |
| | | 37 | | { |
| | | 38 | | try |
| | | 39 | | { |
| | 3 | 40 | | var motivos = await _motivoBajaService.GetAllVigentesAsync(); |
| | | 41 | | |
| | 2 | 42 | | var response = motivos.Select(m => new |
| | 2 | 43 | | { |
| | 2 | 44 | | id = m.Id, |
| | 2 | 45 | | codigo = m.Codigo, |
| | 2 | 46 | | denominacion = m.Denominacion, |
| | 2 | 47 | | vigente = m.Vigente |
| | 2 | 48 | | }); |
| | | 49 | | |
| | 2 | 50 | | return Ok(ApiResponse<object>.SuccessResult(response)); |
| | | 51 | | } |
| | 1 | 52 | | catch (Exception ex) |
| | | 53 | | { |
| | 1 | 54 | | _logger.LogError(ex, "Error al obtener motivos de baja"); |
| | 1 | 55 | | return StatusCode(500, ApiResponse<string>.ErrorResult("Error interno del servidor")); |
| | | 56 | | } |
| | 3 | 57 | | } |
| | | 58 | | } |