50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { apiFetch } from './client'
|
|
|
|
export interface ShoppingItem {
|
|
id: string
|
|
name: string
|
|
amount?: number
|
|
unit?: string
|
|
checked: boolean
|
|
recipe_id?: string
|
|
recipe_title?: string
|
|
created_at?: string
|
|
}
|
|
|
|
export interface ShoppingGroup {
|
|
recipe_title: string
|
|
recipe_id?: string
|
|
items: ShoppingItem[]
|
|
}
|
|
|
|
export function fetchShopping() {
|
|
return apiFetch<ShoppingGroup[]>('/shopping')
|
|
}
|
|
|
|
export function addFromRecipe(recipeId: string) {
|
|
return apiFetch<{ added: number }>(`/shopping/from-recipe/${recipeId}`, { method: 'POST' })
|
|
}
|
|
|
|
export function addCustomItem(item: { name: string; amount?: number; unit?: string }) {
|
|
return apiFetch<ShoppingItem>('/shopping', {
|
|
method: 'POST',
|
|
body: JSON.stringify(item),
|
|
})
|
|
}
|
|
|
|
export function toggleCheck(id: string) {
|
|
return apiFetch<ShoppingItem>(`/shopping/${id}/check`, { method: 'PATCH' })
|
|
}
|
|
|
|
export function deleteItem(id: string) {
|
|
return apiFetch<void>(`/shopping/${id}`, { method: 'DELETE' })
|
|
}
|
|
|
|
export function deleteAll() {
|
|
return apiFetch<void>('/shopping/all', { method: 'DELETE' })
|
|
}
|
|
|
|
export function deleteChecked() {
|
|
return apiFetch<void>('/shopping/checked', { method: 'DELETE' })
|
|
}
|