rowt/src/tera/stat.rs

38 lines
893 B
Rust
Raw Normal View History

2023-07-24 20:56:46 +02:00
use rocket::{get, routes, Route, State};
use rocket_dyn_templates::{context, Template};
use sqlx::SqlitePool;
2023-10-01 14:35:04 +02:00
use crate::model::{
stat::{self, Stat},
2023-10-24 10:57:51 +02:00
user::{NonGuestUser, User},
2023-10-01 14:35:04 +02:00
};
2023-07-24 20:56:46 +02:00
2023-10-01 20:50:23 +02:00
use super::log::KioskCookie;
#[get("/", rank = 2)]
2023-10-24 10:57:51 +02:00
async fn index(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
2023-07-24 20:56:46 +02:00
let stat = Stat::get_rowed_km(db).await;
2023-10-24 10:57:51 +02:00
let personal = stat::get_personal(db, &user.user).await;
2023-10-01 20:50:23 +02:00
let kiosk = false;
Template::render(
"stat",
2023-10-24 11:01:35 +02:00
context!(loggedin_user: &user.user, stat, personal, kiosk),
2023-10-01 20:50:23 +02:00
)
}
#[get("/")]
async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let stat = Stat::get_rowed_km(db).await;
let kiosk = true;
2023-07-24 20:56:46 +02:00
2023-10-23 21:05:59 +02:00
Template::render("stat", context!(stat, kiosk, show_kiosk_header: true))
2023-07-24 20:56:46 +02:00
}
pub fn routes() -> Vec<Route> {
2023-10-01 20:50:23 +02:00
routes![index, index_kiosk]
2023-07-24 20:56:46 +02:00
}
#[cfg(test)]
mod test {}