Initial commit
Made-with: Cursor
This commit is contained in:
56
frontend/src/api/backend.ts
Normal file
56
frontend/src/api/backend.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import axios, { type AxiosInstance } from 'axios'
|
||||
|
||||
import type { CurrentPlanResponse, RunPlanResponse } from '../types/plan'
|
||||
|
||||
const client: AxiosInstance = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
headers: { Accept: 'application/json' },
|
||||
timeout: 30_000,
|
||||
})
|
||||
|
||||
/** Příklad: health / readiness až budou v FastAPI exponované. */
|
||||
export async function getBackendHealth(): Promise<unknown> {
|
||||
const { data } = await client.get('/health')
|
||||
return data
|
||||
}
|
||||
|
||||
export type SetSiteModePayload = {
|
||||
mode: string
|
||||
notes: string | null
|
||||
valid_until: string | null
|
||||
}
|
||||
|
||||
export type SetSiteModeResponse = {
|
||||
success: boolean
|
||||
mode: string
|
||||
activated_at: string
|
||||
}
|
||||
|
||||
export async function postSiteMode(
|
||||
siteId: number,
|
||||
payload: SetSiteModePayload,
|
||||
): Promise<SetSiteModeResponse> {
|
||||
const { data } = await client.post<SetSiteModeResponse>(`/sites/${siteId}/mode`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getCurrentPlan(siteId: number): Promise<CurrentPlanResponse> {
|
||||
const { data } = await client.get<CurrentPlanResponse>(`/sites/${siteId}/plan/current`, {
|
||||
timeout: 60_000,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export async function postRunPlan(
|
||||
siteId: number,
|
||||
planType: 'daily' | 'rolling',
|
||||
): Promise<RunPlanResponse> {
|
||||
const { data } = await client.post<RunPlanResponse>(
|
||||
`/sites/${siteId}/plan/run`,
|
||||
null,
|
||||
{ params: { type: planType }, timeout: 120_000 },
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
export { client as backendClient }
|
||||
Reference in New Issue
Block a user