// ----------------------------------------------------------------------------- // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Project: Groupe Ka / Ka Maps (Lou-Ka — location court terme) // kamaps/ctAdapter.ts : adaptateur /api/ct/listings.geojson → MapProperty. // ----------------------------------------------------------------------------- import type { BoundsQuery, BoundsQueryResult, KaDataAdapter, MapProperty, } from "@groupe-ka/ka-maps"; import { bboxToString } from "@groupe-ka/ka-maps"; import type { CtFilters } from "../ctapi"; interface CtFeatureProps { uid: string; title: string | null; property_type: string | null; city: string | null; region: string | null; price_night: number | null; price_label: string | null; capacity: number | null; bedrooms: number | null; rating: number | null; source: string; image: string | null; } interface CtFC { type: "FeatureCollection"; features: { geometry: { coordinates: [number, number] }; properties: CtFeatureProps; }[]; totalGeocoded?: number; } function toMapProperty(coords: [number, number], p: CtFeatureProps): MapProperty { return { id: p.uid, appSource: "lou-ka", longitude: coords[0], latitude: coords[1], kind: "listing", listingType: "rent", price: p.price_night ?? undefined, propertyType: p.property_type ?? undefined, address: p.title ?? undefined, city: p.city ?? undefined, region: p.region ?? undefined, thumbnailUrl: p.image ?? undefined, originalUrl: `/court-terme/${encodeURIComponent(p.uid)}`, extra: { title: p.title, priceLabel: p.price_label, capacity: p.capacity, bedrooms: p.bedrooms, rating: p.rating, source: p.source, }, }; } /** Adaptateur viewport→données pour la carte court terme. */ export const ctMapAdapter: KaDataAdapter = { id: "lou-ka-ct-listings", appSource: "lou-ka", async fetchInBounds(query: BoundsQuery): Promise { const params = new URLSearchParams(); const filters = (query.filters ?? {}) as Partial; for (const [k, v] of Object.entries(filters)) { if (v) params.set(k, String(v)); } params.set("bbox", bboxToString(query.bbox)); params.set("limit", "4000"); const res = await fetch(`/api/ct/listings.geojson?${params}`, { signal: query.signal, }); if (!res.ok) throw new Error(`Carte : API ${res.status}`); const data = (await res.json()) as CtFC; return { properties: data.features.map((f) => toMapProperty(f.geometry.coordinates, f.properties), ), }; }, };