parent
0c0aaa7048
commit
e4cc833ccc
4 changed files with 143 additions and 1 deletions
27
src/db.rs
27
src/db.rs
|
|
@ -139,6 +139,23 @@ pub async fn create_guild(
|
|||
Ok(map_guild(guild))
|
||||
}
|
||||
|
||||
pub async fn get_guild_by_id(db: &DatabaseConnection, guild_id: Uuid) -> Result<Option<Guild>> {
|
||||
let row = guilds::Entity::find_by_id(guild_id).one(db).await?;
|
||||
Ok(row.map(map_guild))
|
||||
}
|
||||
|
||||
pub async fn is_guild_owner(
|
||||
db: &DatabaseConnection,
|
||||
guild_id: Uuid,
|
||||
user_id: Uuid,
|
||||
) -> Result<bool> {
|
||||
let guild = guilds::Entity::find_by_id(guild_id).one(db).await?;
|
||||
match guild {
|
||||
Some(g) => Ok(g.owner_user_id == user_id),
|
||||
None => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_invite(
|
||||
db: &DatabaseConnection,
|
||||
guild_id: Uuid,
|
||||
|
|
@ -612,6 +629,16 @@ pub async fn create_sound(
|
|||
Ok(map_sound(model))
|
||||
}
|
||||
|
||||
pub async fn get_sound_by_id(db: &DatabaseConnection, id: Uuid) -> Result<Option<SoundboardSound>> {
|
||||
let row = soundboard_sounds::Entity::find_by_id(id).one(db).await?;
|
||||
Ok(row.map(map_sound))
|
||||
}
|
||||
|
||||
pub async fn delete_sound(db: &DatabaseConnection, id: Uuid) -> Result<()> {
|
||||
soundboard_sounds::Entity::delete_by_id(id).exec(db).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn map_sound(model: soundboard_sounds::Model) -> SoundboardSound {
|
||||
SoundboardSound {
|
||||
id: model.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue