munch-ease-frontend/src/api/recipes.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2025-10-18 01:36:55 +00:00
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)
}