2025-03-30 22:26:20 -04:00
|
|
|
use super::render_error;
|
2025-03-23 12:31:48 -04:00
|
|
|
use crate::{State, assets::initial_context, get_lang, get_user_from_token};
|
2025-03-22 22:17:47 -04:00
|
|
|
use axum::{
|
|
|
|
Extension,
|
|
|
|
response::{Html, IntoResponse},
|
|
|
|
};
|
|
|
|
use axum_extra::extract::CookieJar;
|
2025-03-30 22:26:20 -04:00
|
|
|
use tetratto_core::model::Error;
|
2025-03-22 22:17:47 -04:00
|
|
|
|
2025-03-31 11:45:34 -04:00
|
|
|
pub async fn not_found(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
|
|
|
let data = data.read().await;
|
|
|
|
let user = get_user_from_token!(jar, data.0);
|
|
|
|
Html(
|
|
|
|
render_error(
|
|
|
|
Error::GeneralNotFound("page".to_string()),
|
|
|
|
&jar,
|
|
|
|
&data,
|
|
|
|
&user,
|
|
|
|
)
|
|
|
|
.await,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2025-03-22 22:17:47 -04:00
|
|
|
/// `/`
|
|
|
|
pub async fn index_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
|
|
|
let data = data.read().await;
|
2025-03-23 16:37:43 -04:00
|
|
|
let user = get_user_from_token!(jar, data.0);
|
2025-03-22 22:17:47 -04:00
|
|
|
|
2025-03-23 12:31:48 -04:00
|
|
|
let lang = get_lang!(jar, data.0);
|
2025-03-27 18:10:47 -04:00
|
|
|
let mut context = initial_context(&data.0.0, lang, &user).await;
|
2025-03-23 12:31:48 -04:00
|
|
|
|
2025-03-22 22:17:47 -04:00
|
|
|
Html(data.1.render("misc/index.html", &mut context).unwrap())
|
|
|
|
}
|
2025-03-30 22:26:20 -04:00
|
|
|
|
|
|
|
/// `/notifs`
|
|
|
|
pub async fn notifications_request(
|
|
|
|
jar: CookieJar,
|
|
|
|
Extension(data): Extension<State>,
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
let data = data.read().await;
|
|
|
|
let user = match get_user_from_token!(jar, data.0) {
|
|
|
|
Some(ua) => ua,
|
|
|
|
None => {
|
|
|
|
return Err(Html(
|
|
|
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let notifications = match data.0.get_notifications_by_owner(user.id).await {
|
|
|
|
Ok(p) => p,
|
|
|
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
|
|
|
};
|
|
|
|
|
|
|
|
let lang = get_lang!(jar, data.0);
|
|
|
|
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
|
|
|
context.insert("notifications", ¬ifications);
|
|
|
|
|
|
|
|
// return
|
|
|
|
Ok(Html(
|
|
|
|
data.1
|
|
|
|
.render("misc/notifications.html", &mut context)
|
|
|
|
.unwrap(),
|
|
|
|
))
|
|
|
|
}
|