update sum at bottom of page after each change

This commit is contained in:
Khaïs COLIN 2025-10-19 14:18:40 +02:00
parent 12a040fe87
commit 2bd2b95f05
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
5 changed files with 15 additions and 7 deletions

View file

@ -12,9 +12,10 @@ struct IndexTemplate {
}
#[derive(Template)]
#[template(path = "food.html")]
struct FoodTemplate {
#[template(path = "food-update.html")]
struct FoodUpdateTemplate {
food: Food,
sum: i32,
}
#[derive(Debug, Clone, PartialEq)]
@ -83,7 +84,9 @@ async fn increase(
target_servings: row.get(4).unwrap(),
actual_servings: row.get(5).unwrap(),
})).unwrap();
let food = FoodTemplate {food};
let mut stmt = conn.prepare("SELECT SUM(kc_per_serving * actual_servings) as kc FROM food").unwrap();
let sum = stmt.query_one((), |row| row.get(0)).unwrap();
let food = FoodUpdateTemplate{food, sum};
Html(
food.render().unwrap()
)
@ -104,7 +107,9 @@ async fn decrease(
target_servings: row.get(4).unwrap(),
actual_servings: row.get(5).unwrap(),
})).unwrap();
let food = FoodTemplate {food};
let mut stmt = conn.prepare("SELECT SUM(kc_per_serving * actual_servings) as kc FROM food").unwrap();
let sum = stmt.query_one((), |row| row.get(0)).unwrap();
let food = FoodUpdateTemplate {food,sum};
Html(
food.render().unwrap()
)