From f2f820370efbd5c6d0f304f781284a9f68990e21 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 11 Sep 2024 22:43:14 -0400 Subject: 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. --- src/index.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/index.rs') 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, - login: Option, -) -> Result { +async fn index(State(app): State, login: Option) -> Result { 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 { - let mut tx = db.begin().await?; +async fn index_authenticated(app: App, login: Login) -> Result { + 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 { +pub fn router() -> Router { Router::new().route("/", get(index)) } -- cgit v1.2.3