forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplants.js
More file actions
42 lines (34 loc) 路 1.15 KB
/
Copy pathplants.js
File metadata and controls
42 lines (34 loc) 路 1.15 KB
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
const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:3001';
export const getPlants = async (filters = {}) => {
const params = new URLSearchParams();
if (filters.species) params.append('species', filters.species);
if (filters.size) params.append('size', filters.size);
if (filters.status) params.append('status', filters.status);
const url = `${API_URL}/api/plants?${params.toString()}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error('Failed to fetch plants');
}
return response.json();
};
export const getPlantById = async (id) => {
const response = await fetch(`${API_URL}/api/plants/${id}`);
if (!response.ok) {
throw new Error('Failed to fetch plant');
}
return response.json();
};
export const registerPlant = async (plantData, token) => {
const response = await fetch(`${API_URL}/api/plants/register`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(plantData)
});
if (!response.ok) {
throw new Error('Failed to register plant');
}
return response.json();
};