This commit is contained in:
parent
be1451ce45
commit
33da605c03
13 changed files with 534 additions and 9 deletions
52
src/db.rs
52
src/db.rs
|
|
@ -8,10 +8,13 @@ use sea_orm::{
|
|||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
entity::{channels, direct_messages, guild_members, guilds, invites, messages, users},
|
||||
entity::{
|
||||
channels, direct_messages, guild_members, guilds, invites, messages, soundboard_sounds,
|
||||
users,
|
||||
},
|
||||
models::{
|
||||
BasicUser, Channel, DmConversation, DmMessageWithAuthor, Guild, Invite, MessageWithAuthor,
|
||||
User,
|
||||
SoundboardSound, User,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -575,3 +578,48 @@ async fn increment_invite_use_count(
|
|||
active.update(txn).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn list_sounds(db: &DatabaseConnection, guild_id: Uuid) -> Result<Vec<SoundboardSound>> {
|
||||
let rows = soundboard_sounds::Entity::find()
|
||||
.filter(soundboard_sounds::Column::GuildId.eq(guild_id))
|
||||
.order_by_asc(soundboard_sounds::Column::CreatedAt)
|
||||
.all(db)
|
||||
.await?;
|
||||
|
||||
Ok(rows.into_iter().map(map_sound).collect())
|
||||
}
|
||||
|
||||
pub async fn create_sound(
|
||||
db: &DatabaseConnection,
|
||||
guild_id: Uuid,
|
||||
created_by_user_id: Uuid,
|
||||
name: &str,
|
||||
icon: &str,
|
||||
file_path: &str,
|
||||
) -> Result<SoundboardSound> {
|
||||
let model = soundboard_sounds::Entity::insert(soundboard_sounds::ActiveModel {
|
||||
id: Set(Uuid::new_v4()),
|
||||
guild_id: Set(guild_id),
|
||||
created_by_user_id: Set(created_by_user_id),
|
||||
name: Set(name.to_string()),
|
||||
icon: Set(icon.to_string()),
|
||||
file_path: Set(file_path.to_string()),
|
||||
..Default::default()
|
||||
})
|
||||
.exec_with_returning(db)
|
||||
.await?;
|
||||
|
||||
Ok(map_sound(model))
|
||||
}
|
||||
|
||||
fn map_sound(model: soundboard_sounds::Model) -> SoundboardSound {
|
||||
SoundboardSound {
|
||||
id: model.id,
|
||||
guild_id: model.guild_id,
|
||||
name: model.name,
|
||||
icon: model.icon,
|
||||
file_path: model.file_path,
|
||||
created_by_user_id: model.created_by_user_id,
|
||||
created_at: model.created_at,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue