feat: usability

This commit is contained in:
Lukas Wölfer
2026-04-11 14:48:43 +02:00
parent 7010aee5b2
commit b922a610e6
4 changed files with 51 additions and 31 deletions

View File

@@ -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<WeightForm>,
) -> Result<Html<String>, Redirect> {
// Check if user is authenticated
// if let Some(user_id) = session.get::<String>("user_id") {
super::models::insert_weight(&state.pool, "lukas", &form.date, form.weight)
if let Some(user_id) = session.get::<String>("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!(
"<p>{}: {} kg by {}</p>\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"))
}
}

View File

@@ -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.");