style: move structs to objects and split into several files for readability
This commit is contained in:
parent
08cb70ce18
commit
7021c80f02
32 changed files with 1591 additions and 1474 deletions
30
src/objects/invite.rs
Normal file
30
src/objects/invite.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use diesel::{ExpressionMethods, Insertable, QueryDsl, Queryable, Selectable, SelectableHelper};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{Conn, error::Error, schema::invites};
|
||||
|
||||
/// Server invite struct
|
||||
#[derive(Clone, Serialize, Queryable, Selectable, Insertable)]
|
||||
pub struct Invite {
|
||||
/// case-sensitive alphanumeric string with a fixed length of 8 characters, can be up to 32 characters for custom invites
|
||||
pub id: String,
|
||||
/// User that created the invite
|
||||
pub user_uuid: Uuid,
|
||||
/// UUID of the guild that the invite belongs to
|
||||
pub guild_uuid: Uuid,
|
||||
}
|
||||
|
||||
impl Invite {
|
||||
pub async fn fetch_one(conn: &mut Conn, invite_id: String) -> Result<Self, Error> {
|
||||
use invites::dsl;
|
||||
let invite: Invite = dsl::invites
|
||||
.filter(dsl::id.eq(invite_id))
|
||||
.select(Invite::as_select())
|
||||
.get_result(conn)
|
||||
.await?;
|
||||
|
||||
Ok(invite)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue