41 lines
1.3 KiB
C#
Raw Normal View History


2025-05-08 03:09:52 -03:00
using Domain.Entities;
using System.Net.Http.Json;
namespace phronCare.UIBlazor.Services.Integrations
{
2025-05-08 08:55:54 -03:00
public class ExchangeRateService: IExchangeRateService
2025-05-08 03:09:52 -03:00
{
private readonly HttpClient _http;
public ExchangeRateService(HttpClient http)
{
_http = http;
}
public async Task<EExchangeRateHistory> GetYesterdayRateAsync()
{
// Ajustá la URL si tu API está en un path o puerto distinto
var dto = await _http.GetFromJsonAsync<EExchangeRateHistory>("api/ExchangeRate/yesterday");
if (dto == null)
throw new InvalidOperationException("No se obtuvo la cotización de ayer.");
return dto;
}
public async Task<EExchangeRateHistory?> GetByDateAsync(DateOnly date)
{
// Formateamos la fecha para la URL: 2025-05-07
var dateString = date.ToString("yyyy-MM-dd");
// Llamamos a GET /api/ExchangeRate/{date}
var dto = await _http
.GetFromJsonAsync<EExchangeRateHistory>($"api/ExchangeRate/{dateString}");
if (dto == null)
throw new InvalidOperationException($"No se obtuvo la cotización para la fecha {dateString}.");
return dto;
}
}
}