feat: Worker Service - API endpoints

Implement and configure Worker Service to orchestrate data fetchers - Implement API endpoints for stock market data
This commit is contained in:
2025-07-01 12:19:00 -03:00
parent 2fdf80f5b4
commit 10f19af9f8
15 changed files with 680 additions and 44 deletions

View File

@@ -0,0 +1,57 @@
using Mercados.Core.Entities;
using Mercados.Infrastructure.Persistence.Repositories;
using Microsoft.AspNetCore.Mvc;
namespace Mercados.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class MercadosController : ControllerBase
{
private readonly ICotizacionBolsaRepository _bolsaRepo;
private readonly ILogger<MercadosController> _logger;
// Inyectamos los repositorios que este controlador necesita.
public MercadosController(ICotizacionBolsaRepository bolsaRepo, ILogger<MercadosController> logger)
{
_bolsaRepo = bolsaRepo;
_logger = logger;
}
[HttpGet("bolsa/eeuu")]
[ProducesResponseType(typeof(IEnumerable<CotizacionBolsa>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetBolsaUsa()
{
try
{
var data = await _bolsaRepo.ObtenerUltimasPorMercadoAsync("EEUU");
return Ok(data);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error al obtener cotizaciones de bolsa de EEUU.");
return StatusCode(500, "Ocurrió un error interno en el servidor.");
}
}
[HttpGet("bolsa/local")]
[ProducesResponseType(typeof(IEnumerable<CotizacionBolsa>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetBolsaLocal()
{
try
{
var data = await _bolsaRepo.ObtenerUltimasPorMercadoAsync("Local");
return Ok(data);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error al obtener cotizaciones de bolsa local.");
return StatusCode(500, "Ocurrió un error interno en el servidor.");
}
}
// NOTA: Añadiremos los endpoints para Granos y Ganado en un momento.
}
}