From 6366fb3c96e4ed281e233279c85bbfd90ab3ecbc Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 4 Sep 2024 23:38:21 -0400 Subject: Support joining channels. --- src/channel/routes.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/channel/routes.rs') diff --git a/src/channel/routes.rs b/src/channel/routes.rs index 4453a1e..3dc2b1a 100644 --- a/src/channel/routes.rs +++ b/src/channel/routes.rs @@ -12,6 +12,7 @@ use crate::{error::InternalError, login::repo::logins::Login}; pub fn router() -> Router { Router::new() .route("/create", post(on_create)) + .route("/join", post(on_join)) .route("/:channel/leave", post(on_leave)) } @@ -33,6 +34,23 @@ async fn on_create( Ok(Redirect::to("/")) } +#[derive(serde::Deserialize)] +struct JoinRequest { + channel: ChannelId, +} + +async fn on_join( + State(db): State, + login: Login, + Form(req): Form, +) -> Result { + let mut tx = db.begin().await?; + tx.channels().join(&req.channel, &login.id).await?; + tx.commit().await?; + + Ok(Redirect::to("/")) +} + async fn on_leave( State(db): State, login: Login, -- cgit v1.2.3