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:
57
src/Mercados.Api/Controllers/MercadosController.cs
Normal file
57
src/Mercados.Api/Controllers/MercadosController.cs
Normal 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.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user