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.rs43
1 files changed, 5 insertions, 38 deletions
diff --git a/src/channel/routes.rs b/src/channel/routes.rs
index 3dc2b1a..014a57b 100644
--- a/src/channel/routes.rs
+++ b/src/channel/routes.rs
@@ -1,19 +1,16 @@
use axum::{
- extract::{Form, Path, State},
+ extract::{Form, State},
response::{IntoResponse, Redirect},
routing::post,
Router,
};
use sqlx::sqlite::SqlitePool;
-use super::repo::{Id as ChannelId, Provider as _};
+use super::repo::Provider as _;
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))
+ Router::new().route("/create", post(on_create))
}
#[derive(serde::Deserialize)]
@@ -23,41 +20,11 @@ struct CreateRequest {
async fn on_create(
State(db): State<SqlitePool>,
- login: Login,
+ _: 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 channel = tx.channels().create(&form.name).await?;
- tx.channels().join(&channel.id, &login.id).await?;
- tx.commit().await?;
-
- 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,
- Path(channel): Path<ChannelId>,
-) -> Result<impl IntoResponse, InternalError> {
- let mut tx = db.begin().await?;
- tx.channels().leave(&channel, &login.id).await?;
+ tx.channels().create(&form.name).await?;
tx.commit().await?;
Ok(Redirect::to("/"))