-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarket.ts
59 lines (55 loc) · 1.33 KB
/
Market.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
import {MarketType, MarketDetailType} from '@/types/Market';
import apiClient from './ApiClient';
export const getMarketList = async (
cursorId: number = 0,
size: number = 10,
userLatitude?: number,
userLongitude?: number,
): Promise<{
markets: MarketType[];
hasNext: boolean;
} | null> => {
try {
console.log('api call', userLatitude, userLongitude);
const res = await apiClient.get<{
markets: MarketType[];
hasNext: boolean;
} | null>(`/markets`, {
params: {
cursorId,
size,
userLatitude,
userLongitude,
},
});
return res;
} catch (error) {
console.error('Error fetching market list:', error);
return null;
}
};
export const getMarket = async (
marketId: number,
): Promise<MarketDetailType | null> => {
try {
const res = await apiClient.get<MarketDetailType | null>(
`/markets/${marketId}`,
);
return res;
} catch (error) {
console.error(`Error fetching market: ${marketId}`, error);
return null;
}
};
export const updateMarketLike = async (marketId: number): Promise<boolean> => {
try {
const res = await apiClient.post(`/markets/${marketId}/likes`);
if (res) {
return true;
}
return false;
} catch (error) {
console.error('Error in updateMarketLike:', error);
return false;
}
};