47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
|
|
/**
|
||
|
|
* API utilities for fetching celestial data
|
||
|
|
*/
|
||
|
|
import axios from 'axios';
|
||
|
|
import type { CelestialDataResponse, BodyInfo } from '../types';
|
||
|
|
|
||
|
|
const API_BASE_URL = 'http://localhost:8000/api';
|
||
|
|
|
||
|
|
export const api = axios.create({
|
||
|
|
baseURL: API_BASE_URL,
|
||
|
|
timeout: 30000,
|
||
|
|
});
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Fetch celestial positions
|
||
|
|
*/
|
||
|
|
export async function fetchCelestialPositions(
|
||
|
|
startTime?: string,
|
||
|
|
endTime?: string,
|
||
|
|
step: string = '1d'
|
||
|
|
): Promise<CelestialDataResponse> {
|
||
|
|
const params: Record<string, string> = { step };
|
||
|
|
if (startTime) params.start_time = startTime;
|
||
|
|
if (endTime) params.end_time = endTime;
|
||
|
|
|
||
|
|
const response = await api.get<CelestialDataResponse>('/celestial/positions', {
|
||
|
|
params,
|
||
|
|
});
|
||
|
|
return response.data;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Fetch body information
|
||
|
|
*/
|
||
|
|
export async function fetchBodyInfo(bodyId: string): Promise<BodyInfo> {
|
||
|
|
const response = await api.get<BodyInfo>(`/celestial/info/${bodyId}`);
|
||
|
|
return response.data;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* List all bodies
|
||
|
|
*/
|
||
|
|
export async function fetchAllBodies(): Promise<{ bodies: BodyInfo[] }> {
|
||
|
|
const response = await api.get('/celestial/list');
|
||
|
|
return response.data;
|
||
|
|
}
|