add Zustand and del unnecessary files
This commit is contained in:
@@ -3,71 +3,73 @@ import axios from "axios";
|
||||
const API_URL = "https://hopp.zikor.pl";
|
||||
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
export async function addLocation(location) {
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/locations/add`, location, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
});
|
||||
if (!response) {
|
||||
throw new Error("Failed to add location");
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error adding location:", error);
|
||||
throw error;
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/locations/add`, location, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
if (!response) {
|
||||
throw new Error("Failed to add location");
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error adding location:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateLocation(id, location) {
|
||||
try {
|
||||
const response = await axios.put(`${API_URL}/locations/${id}`, location, { headers: { "Content-Type": "application/json" } });
|
||||
if (!response) {
|
||||
throw new Error("Failed to add location");
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error while updating location:", error);
|
||||
throw error;
|
||||
try {
|
||||
const response = await axios.put(`${API_URL}/locations/${id}`, location, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
if (!response) {
|
||||
throw new Error("Failed to add location");
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error while updating location:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteLocation(id) {
|
||||
try {
|
||||
const response = await axios.delete(`${API_URL}/locations/${id}`);
|
||||
if (!response) {
|
||||
throw new Error("Failed to delete location");
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error while deleting location:", error);
|
||||
throw error;
|
||||
try {
|
||||
const response = await axios.delete(`${API_URL}/locations/${id}`);
|
||||
if (!response) {
|
||||
throw new Error("Failed to delete location");
|
||||
}
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error while deleting location:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user