File size: 1,196 Bytes
a0333cd
 
 
0dd2082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const BASE_URL = typeof window !== 'undefined' && window.location.hostname === 'localhost'
    ? 'http://localhost:3001/api'
    : '/api';

async function request(endpoint, options = {}) {
    const url = `${BASE_URL}${endpoint}`;
    const config = {
        headers: { 'Content-Type': 'application/json' },
        ...options,
    };

    const response = await fetch(url, config);
    const data = await response.json();

    if (!response.ok) {
        const error = new Error(data.error || 'Request failed');
        error.status = response.status;
        error.data = data;
        throw error;
    }

    return data;
}

export function getHealth() {
    return request('/health');
}

export function search(query, location, filters, userLocation, clarificationContext) {
    return request('/search', {
        method: 'POST',
        body: JSON.stringify({ query, location, filters, userLocation, clarificationContext }),
    });
}

export function getCategories() {
    return request('/categories');
}

export function getSuggestions(q) {
    return request(`/suggestions?q=${encodeURIComponent(q)}`);
}

export function getPlaceById(id) {
    return request(`/suggestions/${id}`);
}