// ----------------------------------------------------------------------------- // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Project: Groupe Ka / Ka Maps (Rent-Ka integration) // kamaps/adapter.ts: Rent-Ka data adapter → MapProperty. // Transforms /api/listings.geojson (bbox + filters) into the framework's // canonical model — the Rent-Ka domain stays in the app, the map knows nothing. // ----------------------------------------------------------------------------- import type { BoundsQuery, BoundsQueryResult, KaDataAdapter, MapProperty, } from "@groupe-ka/ka-maps"; import { bboxToString } from "@groupe-ka/ka-maps"; import type { ListingFilters } from "../api"; interface LouKaFeatureProps { uid: string; title: string | null; address: string | null; price: number | null; price_label: string | null; unit_type: string | null; availability_date: string | null; source: string; city: string | null; sector: string | null; area_sqft: number | null; image: string | null; } interface LouKaFC { type: "FeatureCollection"; features: { geometry: { coordinates: [number, number] }; properties: LouKaFeatureProps; }[]; totalGeocoded?: number; totalMatching?: number; } function toMapProperty( coords: [number, number], p: LouKaFeatureProps, ): MapProperty { return { id: p.uid, appSource: "rent-ka", longitude: coords[0], latitude: coords[1], kind: "listing", listingType: "rent", price: p.price ?? undefined, propertyType: p.unit_type ?? undefined, address: p.address ?? p.title ?? undefined, city: p.city ?? undefined, region: p.sector ?? undefined, thumbnailUrl: p.image ?? undefined, originalUrl: `/listing/${encodeURIComponent(p.uid)}`, extra: { title: p.title, priceLabel: p.price_label, availabilityDate: p.availability_date, source: p.source, areaSqft: p.area_sqft, sector: p.sector, }, }; } /** Viewport→data adapter for the Rent-Ka map. */ export const louKaMapAdapter: KaDataAdapter = { id: "rent-ka-listings", appSource: "rent-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", "3000"); const res = await fetch(`/api/listings.geojson?${params}`, { signal: query.signal, }); if (!res.ok) throw new Error(`Map: API ${res.status}`); const data = (await res.json()) as LouKaFC; return { properties: data.features.map((f) => toMapProperty(f.geometry.coordinates, f.properties), ), totalCount: data.totalMatching, }; }, };