summaryrefslogtreecommitdiff
path: root/src/index/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/index/routes.rs')
-rw-r--r--src/index/routes.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/index/routes.rs b/src/index/routes.rs
new file mode 100644
index 0000000..c57278f
--- /dev/null
+++ b/src/index/routes.rs
@@ -0,0 +1,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))
+}