Use of api instead of json file for the creating, deletion and edition

This commit is contained in:
2025-05-14 13:42:35 +02:00
parent 395d68a31a
commit 094c66f298
6 changed files with 139 additions and 134 deletions

View File

@@ -29,3 +29,45 @@ export async function getLocation(id) {
}
}
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;
}
}
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;
}
}
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;
}
}