diff --git a/foods.db b/foods.db index 81ff588..51e282b 100644 Binary files a/foods.db and b/foods.db differ diff --git a/src/get_sum.sql b/src/get_sum.sql index 7e72bb7..0e01acb 100644 --- a/src/get_sum.sql +++ b/src/get_sum.sql @@ -1,4 +1,6 @@ SELECT - SUM(kc_per_serving * actual_servings) AS kc + SUM(kc_per_serving * actual_servings) AS kc, + SUM(protein_per_portion * actual_servings) AS protein, + SUM(fiber_per_portion * actual_servings) AS bs FROM food diff --git a/src/main.rs b/src/main.rs index 3ab24fc..5cb85fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,8 +18,8 @@ use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _ #[derive(Debug)] struct Sum { kc: i32, - bs: i32, - protein: i32, + bs: f32, + protein: f32, } impl std::fmt::Display for Sum { @@ -251,12 +251,13 @@ fn get_foods(conn: &ConnState) -> rusqlite::Result> { fn get_sum(conn: &Arc>) -> rusqlite::Result { let conn = conn.lock(); let mut stmt = PreparedStatements::get_sum(&conn); - let kc = stmt.query_one((), |row| row.get(0))?; - let sum = Sum { - kc, - bs: 99, - protein: 99, - }; + let sum = stmt.query_one((), |row| { + Ok(Sum { + kc: row.get(0)?, + bs: row.get(1)?, + protein: row.get(2)?, + }) + })?; debug!(?sum); Ok(sum) } @@ -269,7 +270,10 @@ fn get_date() -> String { async fn root(State(conn): State) -> Result, StatusCode> { let foods = get_foods(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let sum = get_sum(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + let sum = get_sum(&conn).map_err(|e| { + error!(?e); + StatusCode::INTERNAL_SERVER_ERROR + })?; let date = get_date(); let index = IndexTemplate { foods, sum, date }; Ok(Html(