fixed room creation not giving membership

This commit is contained in:
2025-12-15 15:02:36 +01:00
parent 0365c7978c
commit 5ec961255d
3 changed files with 27 additions and 5 deletions

View File

@@ -7,8 +7,8 @@ use axum::{
use sqlx::PgPool;
use uuid::Uuid;
use crate::auth::verify_jwt;
use crate::db::user_id_from_uuid;
use crate::{auth::verify_jwt, db::room_id_from_uuid};
#[derive(sqlx::FromRow, serde::Serialize)]
pub struct Room {
@@ -75,6 +75,15 @@ async fn create_room(
.await
.map_err(|_| (StatusCode::BAD_REQUEST, format!("Could not create room")))?;
let room_id = room_id_from_uuid(&db, room_uuid).await?;
sqlx::query("INSERT INTO membership_ (user_id, room) VALUES ($1, $2)")
.bind(user_id)
.bind(room_id)
.execute(&db)
.await
.map_err(|_| (StatusCode::BAD_REQUEST, format!("Could not create room")))?;
Ok((
StatusCode::CREATED,
Json(Room {