From f81ff82f2a07f87f6eb4f43de49ede64215519e5 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Sat, 27 Dec 2025 16:39:09 +0100 Subject: Refactor route planner to use new GraphQL backend --- src/frontend/app/api/planner.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/frontend/app/api/planner.ts (limited to 'src/frontend/app/api/planner.ts') 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 => { + 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; + } +}; -- cgit v1.3