rowt/src/tera/stat.rs
2023-10-31 16:07:15 +01:00

60 lines
1.4 KiB
Rust

use rocket::{get, routes, Route, State};
use rocket_dyn_templates::{context, Template};
use sqlx::SqlitePool;
use crate::model::{
stat::{self, Stat},
user::NonGuestUser,
};
use super::log::KioskCookie;
#[get("/boats", rank = 2)]
async fn index_boat(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
let stat = Stat::boats(db).await;
let kiosk = false;
Template::render(
"stat.boats",
context!(loggedin_user: &user.user, stat, kiosk),
)
}
#[get("/boats")]
async fn index_boat_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let stat = Stat::boats(db).await;
let kiosk = true;
Template::render("stat.boats", context!(stat, kiosk, show_kiosk_header: true))
}
#[get("/", rank = 2)]
async fn index(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
let stat = Stat::people(db).await;
let personal = stat::get_personal(db, &user.user).await;
let kiosk = false;
Template::render(
"stat.people",
context!(loggedin_user: &user.user, stat, personal, kiosk),
)
}
#[get("/")]
async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let stat = Stat::people(db).await;
let kiosk = true;
Template::render(
"stat.people",
context!(stat, kiosk, show_kiosk_header: true),
)
}
pub fn routes() -> Vec<Route> {
routes![index, index_kiosk, index_boat, index_boat_kiosk]
}
#[cfg(test)]
mod test {}