forked from lavina/lavina
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
use anyhow::Result;
|
|
|
|
use crate::repo::Storage;
|
|
|
|
impl Storage {
|
|
#[tracing::instrument(skip(self), name = "Storage::add_room_member")]
|
|
pub async fn add_room_member(&self, room_id: u32, player_id: u32) -> Result<()> {
|
|
let mut executor = self.conn.lock().await;
|
|
sqlx::query(
|
|
"insert into memberships(user_id, room_id, status)
|
|
values (?, ?, 1);",
|
|
)
|
|
.bind(player_id)
|
|
.bind(room_id)
|
|
.execute(&mut *executor)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tracing::instrument(skip(self), name = "Storage::remove_room_member")]
|
|
pub async fn remove_room_member(&self, room_id: u32, player_id: u32) -> Result<()> {
|
|
let mut executor = self.conn.lock().await;
|
|
sqlx::query(
|
|
"delete from memberships
|
|
where user_id = ? and room_id = ?;",
|
|
)
|
|
.bind(player_id)
|
|
.bind(room_id)
|
|
.execute(&mut *executor)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tracing::instrument(skip(self, topic), name = "Storage::set_room_topic")]
|
|
pub async fn set_room_topic(&mut self, id: u32, topic: &str) -> Result<()> {
|
|
let mut executor = self.conn.lock().await;
|
|
sqlx::query(
|
|
"update rooms
|
|
set topic = ?
|
|
where id = ?;",
|
|
)
|
|
.bind(topic)
|
|
.bind(id)
|
|
.fetch_optional(&mut *executor)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|