const BASE_URL = "http://192.168.68.177:8000" export default { async getMeals(from, to) { const response = await fetch(BASE_URL + "/meals?from=" + from.toISOString() + "&to=" + to.toISOString()); const meals = await response.json(); for (const meal of meals) { meal.date = new Date(meal.date); } return meals; }, async getMeal(id) { var response = await fetch(BASE_URL + `/meals/${encodeURIComponent(id)}`); return await response.json(); }, async deleteMeal(id) { var response = await fetch(BASE_URL + `/meals/${encodeURIComponent(id)}`, { method: "DELETE", }); return await response.json(); }, async searchRecipes(query) { const response = await fetch(BASE_URL + "/recipes?q=" + encodeURIComponent(query)); return await response.json(); }, async parseRecipe(url) { const response = await fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`); return await response.json(); }, async getRecipe(id) { const response = await fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`); return await response.json(); }, async parseProduct(ingredient, url) { const body = { url, tags: [ingredient.name, ingredient.line], }; const response = await fetch(BASE_URL + "/products", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); return await response.json(); }, async parseIngredients(lines) { const params = lines.map(line => "ingredients=" + encodeURIComponent(line)).join("&"); const response = await fetch(BASE_URL + "/recipes/ingredients/parse?" + params); return await response.json(); }, async saveRecipe(recipe) { const response = await fetch(BASE_URL + "/recipes", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(recipe), }); return await response.json(); }, async saveMeal(meal) { const response = await fetch(BASE_URL + "/meals", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(meal), }); return await response.json(); }, }