import { http } from './http' import { mapRecipe, mapRecipes } from './mappers/recipeMapper' export async function searchRecipes(query) { const recipes = await http.get(`/recipes?q=${encodeURIComponent(query)}`) return mapRecipes(recipes) } export async function getRecipe(id) { const recipe = await http.get(`/recipes/${encodeURIComponent(id)}`) return mapRecipe(recipe) } export async function saveRecipe(recipe) { const saved = await http.post('/recipes', recipe) return mapRecipe(saved) } export async function deleteRecipe(id) { return http.del(`/recipes/${encodeURIComponent(id)}`) } export async function parseRecipe(url) { const recipe = await http.get(`/recipes/parse?url=${encodeURIComponent(url)}`) return mapRecipe(recipe) } export async function parseIngredients(lines) { const params = lines.map(line => `ingredients=${encodeURIComponent(line)}`).join('&') return http.get(`/recipes/ingredients/parse?${params}`) } export async function parseProduct(ingredient, url) { const body = { url, tags: [ingredient.name, ingredient.line] } return http.post('/products', body) }