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/channel/routes.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/channel/routes.rs')
| -rw-r--r-- | src/channel/routes.rs | 9 |
1 files changed, 4 insertions, 5 deletions
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<SqlitePool> { +pub fn router() -> Router<App> { Router::new().route("/create", post(on_create)) } @@ -19,11 +18,11 @@ struct CreateRequest { } async fn on_create( - State(db): State<SqlitePool>, + State(app): State<App>, _: Login, // requires auth, but doesn't actually care who you are Form(form): Form<CreateRequest>, ) -> Result<impl IntoResponse, InternalError> { - let mut tx = db.begin().await?; + let mut tx = app.db.begin().await?; tx.channels().create(&form.name).await?; tx.commit().await?; |
