using Core.Interfaces; using Domain.Entities; using Microsoft.AspNetCore.Mvc; namespace phronCare.API.Controllers.Integrations { [ApiController] [Route("api/[controller]")] public class ExchangeRateController : ControllerBase { private readonly IExchangeRateDom _exchangeRateDom; public ExchangeRateController(IExchangeRateDom exchangeRateDom) { _exchangeRateDom = exchangeRateDom; } /// /// Devuelve la cotización oficial del dólar del día anterior, /// leyendo de histórico o consultando BCRA si hace falta. /// [HttpGet("yesterday")] public async Task> GetYesterdayAsync() { try { var rate = await _exchangeRateDom.GetYesterdayRateAsync(); return Ok(rate); } catch (Exception ex) { // Aquí puedes loggear el error o transformarlo en un código HTTP distinto return StatusCode(500, new { message = ex.Message }); } } /// /// Obtiene la cotización del dólar oficial para una fecha dada /// [HttpGet("{date:datetime}")] public async Task> GetByDateAsync(DateTime date) { var dateOnly = DateOnly.FromDateTime(date); var existing = await _exchangeRateDom.GetByDateAsync(dateOnly); if (existing is null) return NotFound(new { message = $"No hay cotización para {dateOnly:yyyy-MM-dd}" }); return Ok(existing); } } }