From bdcb98a047a2cc7e8862d0e456a25ea6cd13a3fa Mon Sep 17 00:00:00 2001 From: Claw AI Date: Thu, 26 Mar 2026 22:46:57 +0000 Subject: [PATCH] Fix API endpoint paths to match controller routing - Endpoints now use /Controller/Action format (e.g. /RentProperties/GetRentProperties) - Unwrap API response envelope ({ data, isSuccess, ... } -> data) - Use query params for single-property fetch (?id=N) - Marked locations endpoint as unconfirmed (not yet deployed) --- app/utils/api.js | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/utils/api.js b/app/utils/api.js index d80f6c6..e4d1d12 100644 --- a/app/utils/api.js +++ b/app/utils/api.js @@ -19,19 +19,29 @@ async function apiFetch(endpoint, options = {}) { throw new Error(`API ${res.status}: ${text || res.statusText}`); } - // Some endpoints return empty body const text = await res.text(); - return text ? JSON.parse(text) : null; + if (!text) return null; + + try { + const json = JSON.parse(text); + // API wraps responses in { data, errors, isSuccess, isFailure, statusCode } + if (json && typeof json === 'object' && 'data' in json) { + return json.data; + } + return json; + } catch { + return text; + } } // ─── Rent Properties ─── export async function getRentProperties() { - return apiFetch('/RentProperties'); + return apiFetch('/RentProperties/GetRentProperties'); } export async function getRentProperty(id) { - return apiFetch(`/RentProperties/${id}`); + return apiFetch(`/RentProperties/GetRentProperties?id=${id}`); } export async function getRentPropertyLocations(params = {}) { @@ -39,21 +49,17 @@ export async function getRentPropertyLocations(params = {}) { if (params.maxOffset != null) qs.set('maxOffset', params.maxOffset); if (params.minOffset != null) qs.set('minOffset', params.minOffset); const query = qs.toString(); - return apiFetch(`/RentProperties/locations${query ? `?${query}` : ''}`); + return apiFetch(`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ''}`); } // ─── Sale Properties ─── export async function getSaleProperties() { - return apiFetch('/SaleProperties'); + return apiFetch('/SaleProperties/GetSaleProperties'); } export async function getSaleProperty(id) { - return apiFetch(`/SaleProperties/${id}`); -} - -export async function getSalePropertiesPaginated(page = 1, pageSize = 10) { - return apiFetch(`/SaleProperties/paginated?pageNumber=${page}&pageSize=${pageSize}`); + return apiFetch(`/SaleProperties/GetSaleProperties?id=${id}`); } // ─── Properties (generic) ─── @@ -65,21 +71,21 @@ export async function getProperty(id) { // ─── Recommendations ─── export async function getRecommendations() { - return apiFetch('/Recommendations'); + return apiFetch('/Recommendations/GetRecommendations'); } export async function getTopRecommendations(count = 10) { - return apiFetch(`/Recommendations/top/${count}`); + return apiFetch(`/Recommendations/GetTopRecommendations?count=${count}`); } // ─── Reservations ─── export async function getReservations() { - return apiFetch('/Reservations'); + return apiFetch('/Reservations/GetReservations'); } export async function getReservation(id) { - return apiFetch(`/Reservations/${id}`); + return apiFetch(`/Reservations/GetReservation?id=${id}`); } export async function checkAvailability(propertyId, fromDate = null, toDate = null) { @@ -87,11 +93,11 @@ export async function checkAvailability(propertyId, fromDate = null, toDate = nu if (fromDate) qs.set('fromDate', fromDate); if (toDate) qs.set('toDate', toDate); const query = qs.toString(); - return apiFetch(`/Reservations/available/${propertyId}${query ? `?${query}` : ''}`); + return apiFetch(`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ''}`); } export async function bookReservation(data) { - return apiFetch('/Reservations/book', { + return apiFetch('/Reservations/Book', { method: 'POST', body: JSON.stringify(data), }); @@ -100,5 +106,5 @@ export async function bookReservation(data) { // ─── Terms ─── export async function getTerms() { - return apiFetch('/Terms'); + return apiFetch('/Terms/GetTerms'); }