75 lines
2 KiB
C#
75 lines
2 KiB
C#
|
|
using AutoMapper;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Microsoft.Extensions.Logging;
|
|||
|
|
using REC_HUMA.CORE.DTOs;
|
|||
|
|
using REC_HUMA.CORE.Interfaces;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System;
|
|||
|
|
|
|||
|
|
namespace REC_HUMA.API.Controllers
|
|||
|
|
{
|
|||
|
|
[Route("api/[controller]")]
|
|||
|
|
[ApiController]
|
|||
|
|
public class PuestoController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly IPuestoRepo _PuestoRepo;
|
|||
|
|
private readonly IMapper _mapper;
|
|||
|
|
private readonly ILogger<PuestoController> _logger;
|
|||
|
|
|
|||
|
|
public PuestoController(IPuestoRepo PuestoRepo, IMapper mapper, ILogger<PuestoController> logger)
|
|||
|
|
{
|
|||
|
|
_PuestoRepo = PuestoRepo;
|
|||
|
|
_mapper = mapper;
|
|||
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public async Task<IEnumerable<PuestoDto>> GetPuestos()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var puestos = await _PuestoRepo.GetPuestos();
|
|||
|
|
|
|||
|
|
var puestosDto = _mapper.Map<IEnumerable<PuestoDto>>(puestos);
|
|||
|
|
|
|||
|
|
return puestosDto;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
var puestosDto = new List<PuestoDto>
|
|||
|
|
{
|
|||
|
|
new PuestoDto() { CodResultado = 500, Mensaje = "Error" }
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return puestosDto;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet("{id}")]
|
|||
|
|
public async Task<PuestoDto> GetPuesto(int id)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var puesto = await _PuestoRepo.GetPuesto(id);
|
|||
|
|
var puestoDto = _mapper.Map<PuestoDto>(puesto);
|
|||
|
|
|
|||
|
|
return puestoDto;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
var puestoDto = new PuestoDto
|
|||
|
|
{
|
|||
|
|
CodResultado = 500,
|
|||
|
|
Mensaje = "Error"
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return puestoDto;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|