munch-ease-frontend/src/data.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-01-13 02:00:15 +00:00
const BASE_URL = "http://localhost:8000"
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
}
}