summaryrefslogtreecommitdiff
path: root/src/channel/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/routes.rs')
-rw-r--r--src/channel/routes.rs18
1 files changed, 18 insertions, 0 deletions
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<SqlitePool> {
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<SqlitePool>,
+ login: Login,
+ Form(req): Form<JoinRequest>,
+) -> Result<impl IntoResponse, InternalError> {
+ 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<SqlitePool>,
login: Login,