
날씨 API
const fetchWeather = async (capital: string): Promise<Weather> => {
const response = await axios.get(
`https://api.openweathermap.org/data/2.5/weather?q=${capital}&units=metric&appid=${process.env.NEXT_PUBLIC_OPENWEATHER_API}`,
);
return response.data;
};
const { data: weather, isLoading: weatherLoading } = useQuery({
queryKey: ['weather', countryCode],
queryFn: () => fetchWeather(capital),
enabled: !!capital,
});
대기질 지수(AQI) API
const fetchAqi = async (capital: string): Promise<AQI> => {
const response = await axios.get(
`https://api.waqi.info/feed/${capital}/?token=${process.env.NEXT_PUBLIC_WAQI_API}`,
);
return response.data.data;
};
const { data: aqi, isLoading: aqiLoading } = useQuery({
queryKey: ['aqi', countryCode],
queryFn: () => fetchAqi(capital),
enabled: !!capital,
});
환율 API
const fetchExchangeRate = async (currency: string): Promise<number> => {
const response = await axios.get(
`https://v6.exchangerate-api.com/v6/${process.env.NEXT_PUBLIC_EXCHANGERATE_API}/latest/${currency}`,
);
return response.data.conversion_rates.KRW;
};
const { data: exchangeRate, isLoading: exchangeRateLoading } = useQuery({
queryKey: ['exchangeRate', countryCode],
queryFn: () => fetchExchangeRate(currency),
enabled: !!currency,
});
항공편 일정 API
const fetchFlights = async (
airportCode: string,
dates: string[],
): Promise<FlightData[]> => {
const allFlights: FlightData[] = [];
for (const date of dates) {
const response = await amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'ICN',
destinationLocationCode: airportCode,
departureDate: date,
adults: '1',
});
allFlights.push({ date, flights: response.data });
}
return allFlights;
};
const { data: flights = [], isLoading: flightsLoading } = useQuery({
queryKey: ['flights', countryCode],
queryFn: () =>
fetchFlights(airportCode, [format(addDays(new Date(), 1), 'yyyy-MM-dd')]),
enabled: !!airportCode,
});