recipe_app/frontend/src/services/frontendApi.js

63 lines
1.7 KiB
JavaScript
Raw Normal View History

2025-07-08 10:40:49 -07:00
export const getRecipes = async () => {
2025-07-15 12:02:11 -07:00
const response = await fetch("http://localhost:3000/recipes");
2025-07-08 10:40:49 -07:00
const data = await response.json();
return data;
};
export const getRecipeSteps = async () => {
const response = await fetch("http://localhost:3000/recipe-steps");
const data = await response.json();
return data;
};
export const getRecipeIngredients = async () => {
const response = await fetch("http://localhost:3000/recipe-ingredients");
const data = await response.json();
return data;
};
2025-07-08 10:40:49 -07:00
export const getRecipeById = async (id) => {
2025-07-15 12:02:11 -07:00
const response = await fetch(`http://localhost:3000/recipe/${id}`);
2025-07-08 10:40:49 -07:00
const data = await response.json();
return data;
};
2025-07-08 11:13:01 -07:00
export const addRecipe = async (recipeData) => {
2025-07-09 17:06:40 -07:00
console.log(JSON.stringify(recipeData))
// return
2025-07-15 12:02:11 -07:00
const response = await fetch("http://localhost:3000/add-recipe", {
2025-07-08 10:40:49 -07:00
method: 'POST',
headers: { 'Content-Type': 'application/json' },
2025-07-08 11:13:01 -07:00
body: JSON.stringify(recipeData)
2025-07-08 10:40:49 -07:00
});
const data = await response.json();
console.log(data);
2025-07-08 10:40:49 -07:00
return data;
};
export const setDBStars = async (id, stars) => {
console.log(JSON.stringify({ id: id, stars: stars }))
// return
const response = await fetch("http://localhost:3000/set-stars", {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: id, stars: stars })
});
const data = await response.json();
console.log(data);
return data;
}
2025-07-08 10:40:49 -07:00
export const deleteRecipe = async (id) => {
console.log(id)
// return
2025-07-15 12:02:11 -07:00
const response = await fetch("http://localhost:3000/delete-recipe", {
2025-07-08 10:40:49 -07:00
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id })
});
const data = await response.json();
return data;
};