From b922a610e63d756790591d0838e32865479fec5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6lfer?= Date: Sat, 11 Apr 2026 14:48:43 +0200 Subject: [PATCH] feat: usability --- src/handlers.rs | 16 +++++++++------- src/main.rs | 2 -- templates/index.html | 44 ++++++++++++++++++++++++++++++++++++++++++-- templates/input.html | 20 -------------------- 4 files changed, 51 insertions(+), 31 deletions(-) delete mode 100644 templates/input.html diff --git a/src/handlers.rs b/src/handlers.rs index 7004a71..a6ad1c1 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -20,6 +20,7 @@ pub struct IndexTemplate { #[derive(Deserialize)] pub struct WeightForm { date: String, + time: String, weight: f64, } @@ -149,8 +150,9 @@ pub async fn input_post( Form(form): Form, ) -> Result, Redirect> { // Check if user is authenticated - // if let Some(user_id) = session.get::("user_id") { - super::models::insert_weight(&state.pool, "lukas", &form.date, form.weight) + if let Some(user_id) = session.get::("user_id") { + let datetime = format!("{}T{}", form.date, form.time); + super::models::insert_weight(&state.pool, &user_id, &datetime, form.weight) .await .unwrap(); let weights = super::models::get_all_weights(&state.pool) @@ -160,12 +162,12 @@ pub async fn input_post( for weight in weights { html.push_str(&format!( "

{}: {} kg by {}

\n", - weight.date, weight.weight, "lukas" + weight.date, weight.weight, &user_id )); } Ok(Html(html)) - // } else { - // // Redirect to login if not authenticated - // Err(Redirect::to("/auth/login")) - // } + } else { + // Redirect to login if not authenticated + Err(Redirect::to("/auth/login")) + } } diff --git a/src/main.rs b/src/main.rs index 788d13f..39e696e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,6 @@ use weight_tracker::{AppState, config::Config, create_app}; #[tokio::main] async fn main() { - // Load configuration from config.toml or environment variables - // config-rs automatically merges file + environment + defaults let config = Config::load("config.toml").unwrap_or_else(|e| { eprintln!("Failed to load configuration: {}", e); eprintln!("Using default values. Set environment variables prefixed with WEIGHT_TRACKER_ to override."); diff --git a/templates/index.html b/templates/index.html index 7eeb9ef..0ada5a5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,10 +1,46 @@ + Weight Tracker + + +

Weight Tracker

@@ -12,16 +48,20 @@

{{ weight.date }}: {{ weight.weight }} kg by {{ weight.user_id }}

{% endfor %}
- +

Add Weight

-
+
+ +

+ \ No newline at end of file diff --git a/templates/input.html b/templates/input.html deleted file mode 100644 index f4dc488..0000000 --- a/templates/input.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - Add Weight - - - - -

Add Weight

-
- -
- -
- -
-
- Back to Tracker - - \ No newline at end of file