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-28 14:48:08 +02:00
|
|
|
user::NonGuestUser,
|
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;
|
|
|
|
|
2023-11-18 12:21:37 +01:00
|
|
|
#[get("/boats?<year>", rank = 2)]
|
|
|
|
async fn index_boat(db: &State<SqlitePool>, user: NonGuestUser, year: Option<i32>) -> Template {
|
|
|
|
let stat = Stat::boats(db, year).await;
|
2023-10-31 16:07:15 +01:00
|
|
|
let kiosk = false;
|
|
|
|
|
|
|
|
Template::render(
|
|
|
|
"stat.boats",
|
|
|
|
context!(loggedin_user: &user.user, stat, kiosk),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-11-18 12:21:37 +01:00
|
|
|
#[get("/boats?<year>")]
|
|
|
|
async fn index_boat_kiosk(
|
|
|
|
db: &State<SqlitePool>,
|
|
|
|
_kiosk: KioskCookie,
|
|
|
|
year: Option<i32>,
|
|
|
|
) -> Template {
|
|
|
|
let stat = Stat::boats(db, year).await;
|
2023-10-31 16:07:15 +01:00
|
|
|
let kiosk = true;
|
|
|
|
|
|
|
|
Template::render("stat.boats", context!(stat, kiosk, show_kiosk_header: true))
|
|
|
|
}
|
|
|
|
|
2023-11-18 12:21:37 +01:00
|
|
|
#[get("/?<year>", rank = 2)]
|
|
|
|
async fn index(db: &State<SqlitePool>, user: NonGuestUser, year: Option<i32>) -> Template {
|
|
|
|
let stat = Stat::people(db, year).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(
|
2023-10-31 16:07:15 +01:00
|
|
|
"stat.people",
|
2023-10-24 11:01:35 +02:00
|
|
|
context!(loggedin_user: &user.user, stat, personal, kiosk),
|
2023-10-01 20:50:23 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-11-18 12:21:37 +01:00
|
|
|
#[get("/?<year>")]
|
|
|
|
async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie, year: Option<i32>) -> Template {
|
|
|
|
let stat = Stat::people(db, year).await;
|
2023-10-01 20:50:23 +02:00
|
|
|
let kiosk = true;
|
2023-07-24 20:56:46 +02:00
|
|
|
|
2023-10-31 16:07:15 +01:00
|
|
|
Template::render(
|
|
|
|
"stat.people",
|
|
|
|
context!(stat, kiosk, show_kiosk_header: true),
|
|
|
|
)
|
2023-07-24 20:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn routes() -> Vec<Route> {
|
2023-10-31 16:07:15 +01:00
|
|
|
routes![index, index_kiosk, index_boat, index_boat_kiosk]
|
2023-07-24 20:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {}
|