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/channel/routes.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/channel') diff --git a/src/channel/routes.rs b/src/channel/routes.rs index 014a57b..6e06cc9 100644 --- a/src/channel/routes.rs +++ b/src/channel/routes.rs @@ -4,12 +4,11 @@ use axum::{ routing::post, Router, }; -use sqlx::sqlite::SqlitePool; use super::repo::Provider as _; -use crate::{error::InternalError, login::repo::logins::Login}; +use crate::{app::App, error::InternalError, login::repo::logins::Login}; -pub fn router() -> Router { +pub fn router() -> Router { Router::new().route("/create", post(on_create)) } @@ -19,11 +18,11 @@ struct CreateRequest { } async fn on_create( - State(db): State, + State(app): State, _: Login, // requires auth, but doesn't actually care who you are Form(form): Form, ) -> Result { - let mut tx = db.begin().await?; + let mut tx = app.db.begin().await?; tx.channels().create(&form.name).await?; tx.commit().await?; -- cgit v1.2.3