fixed rp api
This commit is contained in:
@@ -363,4 +363,75 @@ export const api = {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(updates),
|
||||
}),
|
||||
|
||||
getShoppingSnapshot: () => request<ShoppingSnapshot>("/api/v1/shopping"),
|
||||
|
||||
createShoppingList: (name: string) =>
|
||||
request<{ ok: boolean; list: ShoppingList }>("/api/v1/shopping/lists", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name }),
|
||||
}),
|
||||
|
||||
renameShoppingList: (listId: number, name: string) =>
|
||||
request<{ ok: boolean; list: ShoppingList }>(`/api/v1/shopping/lists/${listId}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name }),
|
||||
}),
|
||||
|
||||
deleteShoppingList: (listId: number) =>
|
||||
request<{ ok: boolean }>(`/api/v1/shopping/lists/${listId}`, { method: "DELETE" }),
|
||||
|
||||
addShoppingItems: (payload: {
|
||||
list_id?: number;
|
||||
list_name?: string;
|
||||
items: { text: string; quantity?: number; unit?: string }[];
|
||||
}) =>
|
||||
request<{ ok: boolean }>("/api/v1/shopping/items", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
|
||||
setShoppingItemChecked: (itemId: number, checked: boolean) =>
|
||||
request<{ ok: boolean }>(`/api/v1/shopping/items/${itemId}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ checked }),
|
||||
}),
|
||||
|
||||
removeShoppingItem: (itemId: number) =>
|
||||
request<{ ok: boolean }>(`/api/v1/shopping/items/${itemId}`, { method: "DELETE" }),
|
||||
|
||||
clearShoppingChecked: (listId: number) =>
|
||||
request<{ ok: boolean }>(`/api/v1/shopping/lists/${listId}/clear-checked`, {
|
||||
method: "POST",
|
||||
}),
|
||||
};
|
||||
|
||||
export interface ShoppingListItem {
|
||||
id: number;
|
||||
list_id: number;
|
||||
text: string;
|
||||
quantity: number | null;
|
||||
unit: string;
|
||||
checked: boolean;
|
||||
sort_order: number;
|
||||
}
|
||||
|
||||
export interface ShoppingList {
|
||||
id: number;
|
||||
name: string;
|
||||
sort_order: number;
|
||||
item_count: number;
|
||||
unchecked_count: number;
|
||||
items?: ShoppingListItem[];
|
||||
}
|
||||
|
||||
export interface ShoppingSnapshot {
|
||||
lists: ShoppingList[];
|
||||
list_count: number;
|
||||
total_items: number;
|
||||
unchecked_items: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user