diff --git a/foods.db b/foods.db index 8574d18..3776fcc 100644 Binary files a/foods.db and b/foods.db differ diff --git a/src/main.rs b/src/main.rs index 69cb3c6..fe30185 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ async fn decrease( Path(id): Path ) -> 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. +
+