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("/")] pub async fn get_challenge( challenge: u32, cookies: &CookieJar<'_>, settings: &State, database: &State, 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), }, ) }