get list of location and get location by id
This commit is contained in:
31
api/locations.jsx
Normal file
31
api/locations.jsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = "http://192.168.7.188:9000";
|
||||
|
||||
export async function listLocations() {
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/locations/all`);
|
||||
if (!response) {
|
||||
throw new Error("No locations found");
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching locations:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLocation(id) {
|
||||
try {
|
||||
const location = await axios.get(`${API_URL}/locations/${id}`);
|
||||
if (!location) {
|
||||
throw new Error("Location not found");
|
||||
}
|
||||
|
||||
return location.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching location:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user