summaryrefslogtreecommitdiff
path: root/src/ui/handlers/index.rs
blob: de0b2b00c62b895b54185de3d1162d70ac145a20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use axum::response::{self, IntoResponse, Redirect};
use axum_extra::TypedHeader;
use headers::IfNoneMatch;

use crate::{error::Internal, token::extract::Identity, ui::assets::Response};

pub async fn handler(
    identity: Option<Identity>,
    TypedHeader(if_none_match): TypedHeader<IfNoneMatch>,
) -> Result<Response, Error> {
    let _ = identity.ok_or(Error::NotLoggedIn)?;

    Response::index(&if_none_match).map_err(Error::Internal)
}

pub enum Error {
    NotLoggedIn,
    Internal(Internal),
}

impl IntoResponse for Error {
    fn into_response(self) -> response::Response {
        match self {
            Self::NotLoggedIn => Redirect::temporary("/login").into_response(),
            Self::Internal(error) => error.into_response(),
        }
    }
}