39 lines
1.1 KiB
39 lines
1.1 KiB
use std::ops::Deref;
|
|
|
|
use rocket::{http::CookieJar, State};
|
|
use rocket_dyn_templates::{context, Template};
|
|
|
|
use crate::{
|
|
cookies::LANG_COOKIE,
|
|
i18n::DEFAULT as DEFAULT_LANG,
|
|
models::{Challenge, Settings, SessionUser, Database},
|
|
utils::AcceptLanguage,
|
|
};
|
|
|
|
#[get("/<challenge>")]
|
|
pub async fn get_challenge(
|
|
challenge: u32,
|
|
cookies: &CookieJar<'_>,
|
|
settings: &State<Settings>,
|
|
database: &State<Database>,
|
|
accept_language: AcceptLanguage,
|
|
) -> Template {
|
|
let (submissions, users) = database.get_challenge_user_data(challenge).unwrap();
|
|
Template::render(
|
|
"index",
|
|
context! {
|
|
challenge,
|
|
submissions,
|
|
users,
|
|
settings: settings.deref(),
|
|
lang: cookies
|
|
.get(LANG_COOKIE)
|
|
.map(|cookie| vec![cookie.value().to_owned()])
|
|
.or(accept_language.0)
|
|
.unwrap_or_else(|| vec![DEFAULT_LANG.to_owned()]),
|
|
user: SessionUser::get(cookies).await.unwrap(),
|
|
content: Challenge::get(challenge),
|
|
},
|
|
)
|
|
}
|