summaryrefslogtreecommitdiff
path: root/src/ui/routes/get.rs
blob: 97737e17197079838c22a314f9bc26b8d5e6b771 (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
29
30
use axum::response::{self, IntoResponse, Redirect};

use crate::{
    error::Internal,
    login::Login,
    ui::assets::{Asset, Assets},
};

pub async fn handler(login: Option<Login>) -> Result<Asset, Error> {
    login.ok_or(Error::NotLoggedIn)?;

    Assets::index().map_err(Error::Internal)
}

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("not logged in")]
    NotLoggedIn,
    #[error("{0}")]
    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(),
        }
    }
}