diff --git a/src/main.rs b/src/main.rs index 5becb43..138f75a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ fn range(bound: i32) -> Vec { struct FoodUpdateTemplate { food: Food, sum: Sum, + date: String, } #[derive(Debug, Clone, PartialEq)] @@ -211,11 +212,16 @@ fn get_sum(conn: &Arc>) -> rusqlite::Result { Ok(sum) } +fn get_date() -> String { + let now = chrono::Local::now(); + let date = format!("{}", now.format("%Y-%M-%d")); + date +} + 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 now = chrono::Local::now(); - let date = format!("{}", now.format("%Y-%M-%d")); + let date = get_date(); let index = IndexTemplate { foods, sum, date }; Ok(Html( index @@ -247,7 +253,8 @@ async fn increase( do_increase(&conn, id).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; let food = get_food(&conn, id).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; let sum = get_sum(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let update = FoodUpdateTemplate { food, sum }; + let date = get_date(); + let update = FoodUpdateTemplate { food, sum, date }; Ok(Html( update .render() @@ -270,7 +277,8 @@ async fn decrease( do_decrease(&conn, id).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; let food = get_food(&conn, id).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; let sum = get_sum(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let update = FoodUpdateTemplate { food, sum }; + let date = get_date(); + let update = FoodUpdateTemplate { food, sum, date }; Ok(Html( update .render() diff --git a/templates/food-update.html b/templates/food-update.html index 2dd7e3d..b6c1d5b 100644 --- a/templates/food-update.html +++ b/templates/food-update.html @@ -1,2 +1,2 @@ {% include "food.html" %} -{% include "sum.html" %} \ No newline at end of file +{% include "header.html" %} \ No newline at end of file diff --git a/templates/header.html b/templates/header.html new file mode 100644 index 0000000..1083c82 --- /dev/null +++ b/templates/header.html @@ -0,0 +1,16 @@ +
+ + Datum: {{ date }} + +
+ + kc: {{ sum.kc }} + + + Protein: {{ sum.protein }} + + + Balaststoffe: {{ sum.bs }} + +
+
\ No newline at end of file diff --git a/templates/index-new.html b/templates/index-new.html deleted file mode 100644 index 098ae7f..0000000 --- a/templates/index-new.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - - - - - Food Tracker - - - - -
- - Datum: {{ date }} - -
- - kc: {{ sum.kc }} - - - Protein: {{ sum.protein }} - - - Balaststoffe: {{ sum.bs }} - -
-
-
-
-
-

- {{ food.name }} -

-
-
-

- 14 Cup -

-

- {{ food.kc_per_serving }} kc -

-
-
- - -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
- - - - - \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 36c2d8d..11badbf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,44 +1,26 @@ - - - - - - - Food Tracker - - - -
- - Datum: {{ date }} - -
- - kc: {{ sum.kc }} - - - Protein: {{ sum.protein }} - - - Balaststoffe: {{ sum.bs }} - -
-
-
-
- {% for food in foods %} + + + + + + Food Tracker + + + {% include "header.html" %} +
+
+ {% for food in foods %} {% include "food.html" %} {% if !loop.last %} -
- {% endif %} +
+ {% endif %} {% endfor %} -
- - - - + \ No newline at end of file diff --git a/templates/sum.html b/templates/sum.html deleted file mode 100644 index e86b650..0000000 --- a/templates/sum.html +++ /dev/null @@ -1,3 +0,0 @@ -
- Total: {{ sum }} kc. -
\ No newline at end of file