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 _logger; // Inyectamos los repositorios que este controlador necesita. public MercadosController(ICotizacionBolsaRepository bolsaRepo, ILogger logger) { _bolsaRepo = bolsaRepo; _logger = logger; } [HttpGet("bolsa/eeuu")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task 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), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task 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. } }