From aebc6326a9960545fc164c17d1f19ecd0e9cf010 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 1 Dec 2022 15:22:12 +0100 Subject: [PATCH] Implement `Database::create_room` --- crates/collab/src/db.rs | 47 +++++++++++++++--------------------- crates/collab/src/db/room.rs | 2 +- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index c5f2f98d0b..30049f2d05 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -953,35 +953,27 @@ impl Database { live_kit_room: &str, ) -> Result> { self.transact(|tx| async move { - todo!() - // let room_id = sqlx::query_scalar( - // " - // INSERT INTO rooms (live_kit_room) - // VALUES ($1) - // RETURNING id - // ", - // ) - // .bind(&live_kit_room) - // .fetch_one(&mut tx) - // .await - // .map(RoomId)?; + let room = room::ActiveModel { + live_kit_room: ActiveValue::set(live_kit_room.into()), + ..Default::default() + } + .insert(&tx) + .await?; + let room_id = room.id; - // sqlx::query( - // " - // INSERT INTO room_participants (room_id, user_id, answering_connection_id, calling_user_id, calling_connection_id) - // VALUES ($1, $2, $3, $4, $5) - // ", - // ) - // .bind(room_id) - // .bind(user_id) - // .bind(connection_id.0 as i32) - // .bind(user_id) - // .bind(connection_id.0 as i32) - // .execute(&mut tx) - // .await?; + room_participant::ActiveModel { + room_id: ActiveValue::set(room_id), + user_id: ActiveValue::set(user_id), + answering_connection_id: ActiveValue::set(Some(connection_id.0 as i32)), + calling_user_id: ActiveValue::set(user_id), + calling_connection_id: ActiveValue::set(connection_id.0 as i32), + ..Default::default() + } + .insert(&tx) + .await?; - // let room = self.get_room(room_id, &mut tx).await?; - // self.commit_room_transaction(room_id, tx, room).await + let room = self.get_room(room_id, &tx).await?; + self.commit_room_transaction(room_id, tx, room).await }) .await } @@ -1411,6 +1403,7 @@ impl Database { }); } } + drop(db_participants); let mut db_projects = db_room .find_related(project::Entity) diff --git a/crates/collab/src/db/room.rs b/crates/collab/src/db/room.rs index b57e612d46..7dbf03a780 100644 --- a/crates/collab/src/db/room.rs +++ b/crates/collab/src/db/room.rs @@ -2,7 +2,7 @@ use super::RoomId; use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] -#[sea_orm(table_name = "room_participants")] +#[sea_orm(table_name = "rooms")] pub struct Model { #[sea_orm(primary_key)] pub id: RoomId,