-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
87 lines (67 loc) · 2.19 KB
/
api.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import axios from 'axios';
const dayPlannerApi = axios.create({
baseURL: 'https://dayplanner-yoqm.onrender.com/api'
})
export const getAllUsers = async () => {
const response = await dayPlannerApi.get('/users');
return response.data;
}
export const getUserByUsername = async (username) => {
const response = await dayPlannerApi.get(`/users/${username}`)
.catch((err) => {
console.log(err)
})
return response.data;
}
export const postUser = async (name, username, searchRadius, longitude, latitude, userFilter) => {
const response = await dayPlannerApi.post('/users', {
displayName: name,
username: username,
settings: {
searchRadius: searchRadius,
location: {
lon: longitude,
lat: latitude,
}
},
filters: userFilter,
});
return response.data;
}
export const patchUser = async (username, avatar, searchRadius, lon, lat, userFilter) => {
const response = await dayPlannerApi.patch(`/users/${username}`, {
avatar: avatar,
settings: {
searchRadius: searchRadius,
location: {
lon: lon,
lat: lat,
}
},
filters: userFilter,
});
return response.data;
}
export const getAllSights = async (username) => {
const response= await dayPlannerApi.get(`/sights?username=${username}`).catch((err) => {console.log(err)});
return response.data;
}
export const getSightById = async (sightId) => {
const response = await dayPlannerApi.get(`/sights/${sightId}`);
return response.data;
}
export const getRoute = async (username, sights) => {
const response = await dayPlannerApi.post(`/routes/${username}`, sights);
return response.data;
}
export const getSavedRoutes = async (username) => {
const response = await dayPlannerApi.get(`/${username}/routes`);
return response.data;
}
export const getRouteById = async (routeId) => {
const response = await dayPlannerApi.get(`/routes/${routeId}`);
return response.data;
}
export const deleteRouteById = async (routeId) => {
const response = await dayPlannerApi.delete(`/routes/${routeId}`);
}