forked from lavina/lavina
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
use anyhow::Result;
|
|
|
|
use crate::repo::Storage;
|
|
|
|
impl Storage {
|
|
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(())
|
|
}
|
|
|
|
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(())
|
|
}
|
|
|
|
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(())
|
|
}
|
|
}
|