From dd0ac1e4c7aa5132a46bd2b2bf50f6db3b4b4a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Sat, 18 Oct 2025 22:45:44 +0200 Subject: [PATCH] use cards, prevent negative servings --- foods.db | Bin 8192 -> 8192 bytes src/main.rs | 2 +- templates/index.html | 45 +++++++++++++++++++++---------------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/foods.db b/foods.db index 8574d18aba63b2a1cd6babe5e420dff1435edf44..3776fcc0dc237e24ff3a6c008bc05b810260b5f7 100644 GIT binary patch delta 98 zcmZp0XmFSy&6qq<#+fmBW5P;)#_gNA1l)N!b(z>1q+OXf87Jq ) -> Redirect{ let conn = conn.lock().unwrap(); - let mut stmt = conn.prepare("UPDATE food SET actual_servings = (SELECT actual_servings FROM food WHERE id = ?1) - 1 WHERE id = ?1").unwrap(); + let mut stmt = conn.prepare("UPDATE food SET actual_servings = MAX((SELECT actual_servings FROM food WHERE id = ?1) - 1, 0) WHERE id = ?1").unwrap(); stmt.execute((id,)).unwrap(); Redirect::to("/") } diff --git a/templates/index.html b/templates/index.html index 11c2627..5b6b573 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,37 +10,36 @@
- - - - - - - +
{% for food in foods %} -
- - - - - + +
+ +
+ + +
+ + {% endfor %} - - - - -
PortionLebensmittelkc.Servings (target)
{{ food.portion }}{{ food.name }}{{ food.kc_per_serving }} +
+
+

+ {{ food.name }} +

+ {{ food.portion }} ({{ food.kc_per_serving }} kc.) +
food.target_servings %} style="accent-color: red;" {% endif %}> {{ food.actual_servings }}/{{ food.target_servings }} -
- - -
-
kc.:{{ sum }}
+
+ Total: {{ sum }} kc. +
+