diff --git a/api/index.php b/api/index.php index b4a681f..dd5681f 100644 --- a/api/index.php +++ b/api/index.php @@ -109,6 +109,9 @@ try { case 'bring_remove': bringRemoveItem(); break; + case 'bring_clean_specs': + bringCleanSpecs(); + break; case 'bring_suggest': bringSuggestItems($db); break; @@ -627,11 +630,10 @@ function useFromInventory(PDO $db): void { // Already on the list, skip adding $addedToBring = false; } else { - $spec = $product['brand'] ?: ''; $body = http_build_query([ 'uuid' => $listUUID, 'purchase' => $bringName, - 'specification' => $spec, + 'specification' => '', ]); $result = bringRequest('PUT', "https://api.getbring.com/rest/v2/bringlists/{$listUUID}", $body); $addedToBring = ($result !== null); @@ -1901,7 +1903,6 @@ function bringAddItems(): void { foreach ($items as $item) { $name = $item['name'] ?? ''; - $spec = $item['specification'] ?? ''; if (empty($name)) continue; // Map Italian name to Bring! catalog key (German) for proper recognition @@ -1916,7 +1917,7 @@ function bringAddItems(): void { $body = http_build_query([ 'uuid' => $listUUID, 'purchase' => $bringName, - 'specification' => $spec, + 'specification' => '', ]); $result = bringRequest('PUT', "https://api.getbring.com/rest/v2/bringlists/{$listUUID}", $body); @@ -1959,6 +1960,42 @@ function bringRemoveItem(): void { echo json_encode(['success' => $result !== null]); } +function bringCleanSpecs(): void { + $auth = bringAuth(); + if (!$auth) { + echo json_encode(['success' => false, 'error' => 'Credenziali Bring! non configurate']); + return; + } + + $listUUID = $auth['bringListUUID']; + if (empty($listUUID)) { + echo json_encode(['success' => false, 'error' => 'Lista non trovata']); + return; + } + + $data = bringRequest('GET', "https://api.getbring.com/rest/v2/bringlists/{$listUUID}"); + if (!$data || !isset($data['purchase'])) { + echo json_encode(['success' => false, 'error' => 'Errore nel recupero della lista']); + return; + } + + $cleaned = 0; + foreach ($data['purchase'] as $item) { + $spec = $item['specification'] ?? ''; + if ($spec !== '') { + $body = http_build_query([ + 'uuid' => $listUUID, + 'purchase' => $item['name'], + 'specification' => '', + ]); + bringRequest('PUT', "https://api.getbring.com/rest/v2/bringlists/{$listUUID}", $body); + $cleaned++; + } + } + + echo json_encode(['success' => true, 'cleaned' => $cleaned]); +} + function bringSuggestItems(PDO $db): void { $env = loadEnvVars(); $apiKey = $env['GEMINI_API_KEY'] ?? ''; @@ -2098,14 +2135,15 @@ LIMITI: - Massimo 12 suggerimenti - Ordina per PRIORITÀ REALE (prima le mancanze gravi, poi i nice-to-have) - Ogni motivo deve essere SPECIFICO ("non hai proteine fresche" non "è buono") -- Nel campo "specification" indica SEMPRE la quantità consigliata per una famiglia (es: "500g", "6 uova bio", "2 mazzetti", "1 bottiglia da 1L") +- NON inserire quantità, marche o dettagli nel campo "specification" — lascialo sempre vuoto. +- Usa nomi GENERICI dal catalogo Bring! (es: "Latte" non "Latte Granarolo 1L"). Rispondi SOLO con un JSON valido (senza markdown, senza backtick): { "suggestions": [ { - "name": "nome prodotto in italiano", - "specification": "quantità consigliata e dettagli (es: 500g, 6 uova bio, 2 mazzetti, 1 bottiglia da 1L)", + "name": "nome prodotto generico in italiano", + "specification": "", "reason": "motivo breve", "category": "frutta|verdura|latticini|carne|pesce|pane|pasta|conserve|condimenti|bevande|snack|surgelati|cereali|igiene|pulizia|altro", "priority": "alta|media|bassa" diff --git a/assets/js/app.js b/assets/js/app.js index 60e14ec..bba1cc0 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -4030,14 +4030,7 @@ async function addSelectedSuggestions() { try { const items = selected.map(s => { - // Build rich specification: combine quantity/detail + priority emoji - let spec = s.specification || ''; - const priorityEmoji = { 'alta': '🔴', 'media': '🟡', 'bassa': '🟢' }; - const emoji = priorityEmoji[s.priority] || ''; - if (emoji) { - spec = spec ? `${emoji} ${spec}` : emoji; - } - return { name: s.name, specification: spec }; + return { name: s.name }; }); const data = await api('bring_add', {}, 'POST', { items, listUUID: shoppingListUUID }); diff --git a/data/dispensa.db b/data/dispensa.db index ba757b6..9a64122 100644 Binary files a/data/dispensa.db and b/data/dispensa.db differ diff --git a/index.html b/index.html index 1c946ac..87b8345 100644 --- a/index.html +++ b/index.html @@ -884,6 +884,6 @@ - +