feat: stabilization + recipe edit/create UI
This commit is contained in:
45
frontend/src/api/shopping.ts
Normal file
45
frontend/src/api/shopping.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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 deleteChecked() {
|
||||
return apiFetch<void>('/shopping/checked', { method: 'DELETE' })
|
||||
}
|
||||
Reference in New Issue
Block a user