28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
|
|
import apiClient from '../api/apiClient';
|
||
|
|
import type { Pronostico } from '../types/weather';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Obtiene el pronóstico de 5 días para una estación específica desde la API.
|
||
|
|
*
|
||
|
|
* @param stationName El nombre de la estación a consultar (ej. "LA_PLATA_AERO").
|
||
|
|
* @returns Una promesa que se resuelve con un array de objetos Pronostico.
|
||
|
|
* @throws Lanza un error si la llamada a la API falla.
|
||
|
|
*/
|
||
|
|
export const getForecastByStation = async (stationName: string): Promise<Pronostico[]> => {
|
||
|
|
try {
|
||
|
|
// Construimos la URL del endpoint.
|
||
|
|
// Ejemplo: /api/Weather/LA_PLATA_AERO
|
||
|
|
const endpoint = `/api/Weather/${encodeURIComponent(stationName)}`;
|
||
|
|
|
||
|
|
// Hacemos la llamada GET usando nuestro cliente axios.
|
||
|
|
const response = await apiClient.get<Pronostico[]>(endpoint);
|
||
|
|
|
||
|
|
// Devolvemos los datos que vienen en la respuesta.
|
||
|
|
return response.data;
|
||
|
|
} catch (error) {
|
||
|
|
// Si hay un error, lo registramos en la consola y lo relanzamos
|
||
|
|
// para que el componente que llama pueda manejarlo.
|
||
|
|
console.error(`Error al obtener el pronóstico para la estación ${stationName}:`, error);
|
||
|
|
throw error;
|
||
|
|
}
|
||
|
|
};
|