show protein and fiber sums
This commit is contained in:
parent
07bfc65b67
commit
fa0d8930b8
3 changed files with 16 additions and 10 deletions
BIN
foods.db
BIN
foods.db
Binary file not shown.
|
|
@ -1,4 +1,6 @@
|
||||||
SELECT
|
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
|
FROM
|
||||||
food
|
food
|
||||||
|
|
|
||||||
22
src/main.rs
22
src/main.rs
|
|
@ -18,8 +18,8 @@ use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Sum {
|
struct Sum {
|
||||||
kc: i32,
|
kc: i32,
|
||||||
bs: i32,
|
bs: f32,
|
||||||
protein: i32,
|
protein: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Sum {
|
impl std::fmt::Display for Sum {
|
||||||
|
|
@ -251,12 +251,13 @@ fn get_foods(conn: &ConnState) -> rusqlite::Result<Vec<Food>> {
|
||||||
fn get_sum(conn: &Arc<Mutex<Connection>>) -> rusqlite::Result<Sum> {
|
fn get_sum(conn: &Arc<Mutex<Connection>>) -> rusqlite::Result<Sum> {
|
||||||
let conn = conn.lock();
|
let conn = conn.lock();
|
||||||
let mut stmt = PreparedStatements::get_sum(&conn);
|
let mut stmt = PreparedStatements::get_sum(&conn);
|
||||||
let kc = stmt.query_one((), |row| row.get(0))?;
|
let sum = stmt.query_one((), |row| {
|
||||||
let sum = Sum {
|
Ok(Sum {
|
||||||
kc,
|
kc: row.get(0)?,
|
||||||
bs: 99,
|
bs: row.get(1)?,
|
||||||
protein: 99,
|
protein: row.get(2)?,
|
||||||
};
|
})
|
||||||
|
})?;
|
||||||
debug!(?sum);
|
debug!(?sum);
|
||||||
Ok(sum)
|
Ok(sum)
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +270,10 @@ fn get_date() -> String {
|
||||||
|
|
||||||
async fn root(State(conn): State<ConnState>) -> Result<Html<String>, StatusCode> {
|
async fn root(State(conn): State<ConnState>) -> Result<Html<String>, StatusCode> {
|
||||||
let foods = get_foods(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
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 date = get_date();
|
||||||
let index = IndexTemplate { foods, sum, date };
|
let index = IndexTemplate { foods, sum, date };
|
||||||
Ok(Html(
|
Ok(Html(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue