diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-27 16:39:09 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-27 16:39:28 +0100 |
| commit | f81ff82f2a07f87f6eb4f43de49ede64215519e5 (patch) | |
| tree | 67b4f9ef1c94184e2e1a9878c6feed8dc30ebcb3 /src/frontend/app/api/planner.ts | |
| parent | ef2df90ffb195edcddd701511dc5953c7baa63af (diff) | |
Refactor route planner to use new GraphQL backend
Diffstat (limited to 'src/frontend/app/api/planner.ts')
| -rw-r--r-- | src/frontend/app/api/planner.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/frontend/app/api/planner.ts b/src/frontend/app/api/planner.ts new file mode 100644 index 0000000..86f44f0 --- /dev/null +++ b/src/frontend/app/api/planner.ts @@ -0,0 +1,34 @@ +import { RoutePlanSchema, type RoutePlan } from "./schema"; + +export const fetchPlan = async ( + fromLat: number, + fromLon: number, + toLat: number, + toLon: number, + time?: Date, + arriveBy: boolean = false +): Promise<RoutePlan> => { + let url = `/api/planner/plan?fromLat=${fromLat}&fromLon=${fromLon}&toLat=${toLat}&toLon=${toLon}&arriveBy=${arriveBy}`; + if (time) { + url += `&time=${time.toISOString()}`; + } + + const resp = await fetch(url, { + headers: { + Accept: "application/json", + }, + }); + + if (!resp.ok) { + throw new Error(`HTTP ${resp.status}: ${resp.statusText}`); + } + + const data = await resp.json(); + try { + return RoutePlanSchema.parse(data); + } catch (e) { + console.error("Zod parsing failed for route plan:", e); + console.log("Received data:", data); + throw e; + } +}; |
