chore: initialized repository

This commit is contained in:
Lukas Wölfer
2026-04-08 22:45:47 +02:00
commit 024d64b284
11 changed files with 2483 additions and 0 deletions

41
src/handlers.rs Normal file
View File

@@ -0,0 +1,41 @@
use axum::response::Html;
use askama::Template;
use sqlx::SqlitePool;
use axum::{extract::State, Form};
use serde::Deserialize;
#[derive(Template)]
#[template(path = "index.html")]
pub struct IndexTemplate {
pub weights: Vec<super::models::Weight>,
}
#[derive(Template)]
#[template(path = "input.html")]
pub struct InputTemplate;
#[derive(Deserialize)]
pub struct WeightForm {
date: String,
weight: f64,
}
pub async fn index(State(pool): State<SqlitePool>) -> Html<String> {
let weights = super::models::get_all_weights(&pool).await.unwrap_or_default();
let template = IndexTemplate { weights };
Html(template.render().unwrap())
}
pub async fn input_get() -> Html<String> {
let template = InputTemplate;
Html(template.render().unwrap())
}
pub async fn input_post(
State(pool): State<SqlitePool>,
Form(form): Form<WeightForm>,
) -> Html<String> {
let user_id = "test_user"; // TODO: Implement OIDC to get real user_id
super::models::insert_weight(&pool, user_id, &form.date, form.weight).await.unwrap();
Html("<p>Weight added successfully!</p>".to_string())
}