feat: Complete API endpoints for grains and cattle data

This commit is contained in:
2025-07-01 12:45:32 -03:00
parent 8595dd16a8
commit 5e9270eda7
5 changed files with 85 additions and 6 deletions

View File

@@ -9,15 +9,60 @@ namespace Mercados.Api.Controllers
public class MercadosController : ControllerBase
{
private readonly ICotizacionBolsaRepository _bolsaRepo;
private readonly ICotizacionGranoRepository _granoRepo;
private readonly ICotizacionGanadoRepository _ganadoRepo;
private readonly ILogger<MercadosController> _logger;
// Inyectamos los repositorios que este controlador necesita.
public MercadosController(ICotizacionBolsaRepository bolsaRepo, ILogger<MercadosController> logger)
// Inyectamos TODOS los repositorios que necesita el controlador.
public MercadosController(
ICotizacionBolsaRepository bolsaRepo,
ICotizacionGranoRepository granoRepo,
ICotizacionGanadoRepository ganadoRepo,
ILogger<MercadosController> logger)
{
_bolsaRepo = bolsaRepo;
_granoRepo = granoRepo;
_ganadoRepo = ganadoRepo;
_logger = logger;
}
// --- Endpoint para Agroganadero ---
[HttpGet("agroganadero")]
[ProducesResponseType(typeof(IEnumerable<CotizacionGanado>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetAgroganadero()
{
try
{
var data = await _ganadoRepo.ObtenerUltimaTandaAsync();
return Ok(data);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error al obtener cotizaciones de agroganadero.");
return StatusCode(500, "Ocurrió un error interno en el servidor.");
}
}
// --- Endpoint para Granos ---
[HttpGet("granos")]
[ProducesResponseType(typeof(IEnumerable<CotizacionGrano>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetGranos()
{
try
{
var data = await _granoRepo.ObtenerUltimasAsync();
return Ok(data);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error al obtener cotizaciones de granos.");
return StatusCode(500, "Ocurrió un error interno en el servidor.");
}
}
// --- Endpoints de Bolsa ---
[HttpGet("bolsa/eeuu")]
[ProducesResponseType(typeof(IEnumerable<CotizacionBolsa>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
@@ -51,7 +96,5 @@ namespace Mercados.Api.Controllers
return StatusCode(500, "Ocurrió un error interno en el servidor.");
}
}
// NOTA: Añadiremos los endpoints para Granos y Ganado en un momento.
}
}