2024-01-14 01:46:45 +00:00
|
|
|
const BASE_URL = "http://192.168.68.177:8000"
|
2024-01-13 02:00:15 +00:00
|
|
|
|
|
|
|
|
export default {
|
2024-01-17 09:17:22 +00:00
|
|
|
async getMeals(from, to) {
|
|
|
|
|
const response = fetch(BASE_URL + "/meals?from=" + from.toISOString() + "&to=" + to.toISOString());
|
|
|
|
|
return response.json();
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async getMeal(id) {
|
|
|
|
|
var response = await fetch(BASE_URL + `/meals/${encodeURIComponent(id)}`);
|
|
|
|
|
return response.json();
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async searchRecipes(query) {
|
|
|
|
|
const response = await fetch(BASE_URL + "/recipes?q=" + encodeURIComponent(query));
|
|
|
|
|
return response.json();
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async parseRecipe(url) {
|
|
|
|
|
const response = await fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`);
|
|
|
|
|
return response.json();
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async getRecipe(id) {
|
|
|
|
|
const response = await fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`);
|
|
|
|
|
return response.json();
|
2024-01-13 07:00:55 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async parseProduct(ingredient, url) {
|
2024-01-13 02:00:15 +00:00
|
|
|
const body = {
|
|
|
|
|
url, tags: [ingredient.name, ingredient.line],
|
2024-01-17 09:17:22 +00:00
|
|
|
};
|
2024-01-13 03:22:10 +00:00
|
|
|
|
2024-01-17 09:17:22 +00:00
|
|
|
const response = await fetch(BASE_URL + "/products", {
|
2024-01-13 02:00:15 +00:00
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(body),
|
2024-01-17 09:17:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return response.json();
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async parseIngredients(lines) {
|
2024-01-13 02:00:15 +00:00
|
|
|
const params = lines.map(line => "ingredients=" + encodeURIComponent(line)).join("&");
|
2024-01-17 09:17:22 +00:00
|
|
|
const response = await fetch(BASE_URL + "/recipes/ingredients/parse?" + params);
|
|
|
|
|
return response.json();
|
2024-01-13 03:22:10 +00:00
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async saveRecipe(recipe) {
|
|
|
|
|
const response = await fetch(BASE_URL + "/recipes", {
|
2024-01-13 03:22:10 +00:00
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(recipe),
|
2024-01-17 09:17:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return response.json();
|
|
|
|
|
},
|
|
|
|
|
async saveMeal(meal) {
|
|
|
|
|
const response = await fetch(BASE_URL + "/meals", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(meal),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return response.json();
|
|
|
|
|
},
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|