From d99aef9d114a494270e4eabba779308a24bee6af Mon Sep 17 00:00:00 2001 From: mohamad Date: Thu, 8 May 2025 23:21:12 +0200 Subject: [PATCH] Add price input field for completed items in ListDetailPage; update item API endpoint to use new configuration; ensure price handling is consistent and type-safe during updates. --- fe/src/config/api-config.ts | 5 +++++ fe/src/pages/ListDetailPage.vue | 36 +++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/fe/src/config/api-config.ts b/fe/src/config/api-config.ts index 76b3d23..3a13080 100644 --- a/fe/src/config/api-config.ts +++ b/fe/src/config/api-config.ts @@ -71,6 +71,11 @@ export const API_ENDPOINTS = { SENT: '/invites/sent', }, + // Items (for direct operations like update, get by ID) + ITEMS: { + BY_ID: (itemId: string) => `/items/${itemId}`, + }, + // OCR OCR: { PROCESS: '/ocr/extract-items', diff --git a/fe/src/pages/ListDetailPage.vue b/fe/src/pages/ListDetailPage.vue index 889edab..3689299 100644 --- a/fe/src/pages/ListDetailPage.vue +++ b/fe/src/pages/ListDetailPage.vue @@ -155,6 +155,20 @@ Quantity: {{ item.quantity }} + + { const updateItem = async (item: Item) => { item.updating = true; try { + // Use the new endpoint for updating a specific item const response = await apiClient.put( - API_ENDPOINTS.LISTS.ITEM(String(list.value.id), String(item.id)), + API_ENDPOINTS.ITEMS.BY_ID(String(item.id)), { - name: editingItemName.value, - quantity: editingItemQuantity.value?.toString(), - completed: item.is_complete, + // Send only relevant fields for this update action + is_complete: item.is_complete, + // Ensure price is a number or null. If item.price is undefined, treat as null. + price: (item.price === undefined || item.price === null) ? null : Number(item.price), version: item.version, } ); Object.assign(item, response.data as Item); + // Ensure the price is a number locally after update, or null + if (response.data.price !== null && response.data.price !== undefined) { + item.price = Number(response.data.price); + } else { + item.price = null; + } } catch (err: unknown) { if ((err as { response?: { status?: number } }).response?.status === 409) { $q.notify({ @@ -391,7 +414,7 @@ const handleOcrUpload = async (file: File | null) => { ocrError.value = null; try { const formData = new FormData(); - formData.append('file', file); + formData.append('image_file', file); const response = await apiClient.post( API_ENDPOINTS.OCR.PROCESS, @@ -402,7 +425,8 @@ const handleOcrUpload = async (file: File | null) => { } } ); - ocrItems.value = response.data.items; + // Transform the array of strings into an array of objects { name: string } + ocrItems.value = response.data.extracted_items.map((nameStr: string) => ({ name: nameStr })); showOcrDialog.value = true; } catch (err: unknown) { ocrError.value = (err as Error).message || 'Failed to process image';