summaryrefslogtreecommitdiff
path: root/src/index/routes.rs
blob: c57278f6c47beb668bea80d128616db479fe5ae6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use axum::{extract::State, routing::get, Router};
use maud::Markup;

use super::templates;
use crate::{app::App, error::InternalError, login::repo::logins::Login};

async fn index(State(app): State<App>, login: Option<Login>) -> Result<Markup, InternalError> {
    match login {
        None => Ok(templates::unauthenticated()),
        Some(login) => index_authenticated(app, login).await,
    }
}

async fn index_authenticated(app: App, login: Login) -> Result<Markup, InternalError> {
    let channels = app.index().for_authenticated().await?;

    Ok(templates::authenticated(login, &channels))
}

pub fn router() -> Router<App> {
    Router::new().route("/", get(index))
}