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-13 23:09:15 +00:00
|
|
|
getMeals(from, to) {
|
|
|
|
|
return fetch(BASE_URL + "/meals?from=" + from.toISOString() + "&to=" + to.toISOString())
|
2024-01-13 02:00:15 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
|
},
|
|
|
|
|
getMeal(id) {
|
|
|
|
|
return fetch(BASE_URL + `/meals/${encodeURIComponent(id)}`)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
},
|
2024-01-13 23:09:15 +00:00
|
|
|
searchRecipes(query) {
|
|
|
|
|
return fetch(BASE_URL + "/recipes?q=" + encodeURIComponent(query))
|
|
|
|
|
.then(response => response.json())
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
|
|
|
|
parseRecipe(url) {
|
|
|
|
|
return fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
},
|
2024-01-13 07:00:55 +00:00
|
|
|
getRecipe(id) {
|
|
|
|
|
return fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
},
|
2024-01-13 02:00:15 +00:00
|
|
|
parseProduct(ingredient, url) {
|
|
|
|
|
const body = {
|
|
|
|
|
url, tags: [ingredient.name, ingredient.line],
|
|
|
|
|
}
|
2024-01-13 03:22:10 +00:00
|
|
|
|
2024-01-13 02:00:15 +00:00
|
|
|
return fetch(BASE_URL + "/products", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
}).then(response => response.json())
|
|
|
|
|
},
|
|
|
|
|
parseIngredients(lines) {
|
|
|
|
|
const params = lines.map(line => "ingredients=" + encodeURIComponent(line)).join("&");
|
|
|
|
|
return fetch(BASE_URL + "/recipes/ingredients/parse?" + params)
|
|
|
|
|
.then(response => response.json())
|
2024-01-13 03:22:10 +00:00
|
|
|
},
|
|
|
|
|
saveRecipe(recipe) {
|
|
|
|
|
return fetch(BASE_URL + "/recipes", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(recipe),
|
|
|
|
|
}).then(response => response.json())
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
}
|