Login
4 branches 0 tags
Ben (Desktop/Arch) Switched from Bun to Vite for bundling 809b7f2 1 month ago 128 Commits
rubhub / src / controllers / not_found.rs
use askama::Template;
use axum::{
    body::Body,
    extract::State,
    http::{Response, StatusCode},
    response::{Html, IntoResponse},
};
use tower_cookies::Cookies;

use crate::{GlobalState, User, services::session, views::ThemedRender};

#[derive(Template)]
#[template(path = "404.html")]
struct NotFoundTemplate<'a> {
    logged_in_user: Option<&'a User>,
}

pub fn not_found(logged_in_user: Option<User>) -> Response<Body> {
    let template = NotFoundTemplate {
        logged_in_user: logged_in_user.as_ref(),
    };
    (StatusCode::NOT_FOUND, Html(template.render_with_theme())).into_response()
}

pub async fn not_found_get(State(state): State<GlobalState>, cookies: Cookies) -> Response<Body> {
    let logged_in_user = session::current_user(&state, &cookies).await.ok();
    not_found(logged_in_user)
}