2025-08-05 18:11:03 +00:00
|
|
|
const baseUrl = process.env.NODE_ENV !== 'dev'
|
2025-07-25 16:00:55 -07:00
|
|
|
? '/'
|
|
|
|
: 'http://localhost:3000/';
|
|
|
|
|
2025-07-08 10:40:49 -07:00
|
|
|
export const getRecipes = async () => {
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/recipes`);
|
2025-07-08 10:40:49 -07:00
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2025-07-24 12:11:32 -07:00
|
|
|
export const getRecipeSteps = async () => {
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/recipe-steps`);
|
2025-07-24 12:11:32 -07:00
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getRecipeIngredients = async () => {
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/recipe-ingredients`);
|
2025-07-24 12:11:32 -07:00
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2025-07-08 10:40:49 -07:00
|
|
|
export const getRecipeById = async (id) => {
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/recipe/${id}`);
|
2025-07-08 10:40:49 -07:00
|
|
|
const data = await response.json();
|
2025-08-06 16:18:06 -07:00
|
|
|
if (!data || !data.details) {
|
|
|
|
return { details: null };
|
|
|
|
}
|
2025-07-08 10:40:49 -07:00
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2025-07-08 11:13:01 -07:00
|
|
|
export const addRecipe = async (recipeData) => {
|
2025-07-25 18:07:20 +00:00
|
|
|
console.log(JSON.stringify(recipeData));
|
2025-07-09 17:06:40 -07:00
|
|
|
// return
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/add-recipe`, {
|
2025-07-25 18:07:20 +00:00
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify(recipeData),
|
2025-07-08 10:40:49 -07:00
|
|
|
});
|
|
|
|
const data = await response.json();
|
2025-07-24 12:11:32 -07:00
|
|
|
console.log(data);
|
2025-07-08 10:40:49 -07:00
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2025-07-24 12:11:32 -07:00
|
|
|
export const setDBStars = async (id, stars) => {
|
2025-07-25 18:07:20 +00:00
|
|
|
console.log(JSON.stringify({ id: id, stars: stars }));
|
2025-07-24 12:11:32 -07:00
|
|
|
// return
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/set-stars`, {
|
2025-07-25 18:07:20 +00:00
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({ id: id, stars: stars }),
|
2025-07-24 12:11:32 -07:00
|
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
console.log(data);
|
|
|
|
return data;
|
2025-07-25 18:07:20 +00:00
|
|
|
};
|
2025-07-24 12:11:32 -07:00
|
|
|
|
2025-07-08 10:40:49 -07:00
|
|
|
export const deleteRecipe = async (id) => {
|
2025-07-25 18:07:20 +00:00
|
|
|
console.log(id);
|
2025-07-08 10:40:49 -07:00
|
|
|
// return
|
2025-07-25 16:00:55 -07:00
|
|
|
const response = await fetch(`${baseUrl}backend/delete-recipe`, {
|
2025-07-25 18:07:20 +00:00
|
|
|
method: "DELETE",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({ id }),
|
2025-07-08 10:40:49 -07:00
|
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
};
|