diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-11 22:43:14 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-12 00:26:04 -0400 |
| commit | f2f820370efbd5c6d0f304f781284a9f68990e21 (patch) | |
| tree | 7fb25e676dcd8dc694d0cec4df2cc04cab1120ac /src/index.rs | |
| parent | 8a4e25c2a7d6235d726499d43fd1721104314e86 (diff) | |
Wrap the database pool in an App struct.
This is a jumping-off point for adding logic that needs more than just the DB for state, such as chat message handling.
The name sucks, but it's the best I've got.
Diffstat (limited to 'src/index.rs')
| -rw-r--r-- | src/index.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/index.rs b/src/index.rs index 9efd7cc..843cb77 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,28 +1,26 @@ use axum::{extract::State, routing::get, Router}; use maud::Markup; -use sqlx::sqlite::SqlitePool; -use crate::{channel::repo::Provider as _, error::InternalError, login::repo::logins::Login}; +use crate::{ + app::App, channel::repo::Provider as _, error::InternalError, login::repo::logins::Login, +}; -async fn index( - State(db): State<SqlitePool>, - login: Option<Login>, -) -> Result<Markup, InternalError> { +async fn index(State(app): State<App>, login: Option<Login>) -> Result<Markup, InternalError> { match login { None => Ok(templates::unauthenticated()), - Some(login) => index_authenticated(db, login).await, + Some(login) => index_authenticated(app, login).await, } } -async fn index_authenticated(db: SqlitePool, login: Login) -> Result<Markup, InternalError> { - let mut tx = db.begin().await?; +async fn index_authenticated(app: App, login: Login) -> Result<Markup, InternalError> { + let mut tx = app.db.begin().await?; let channels = tx.channels().all().await?; tx.commit().await?; Ok(templates::authenticated(login, &channels)) } -pub fn router() -> Router<SqlitePool> { +pub fn router() -> Router<App> { Router::new().route("/", get(index)) } |
