backend/objects/
invite.rs

1use diesel::{ExpressionMethods, Insertable, QueryDsl, Queryable, Selectable, SelectableHelper};
2use diesel_async::RunQueryDsl;
3use serde::Serialize;
4use uuid::Uuid;
5
6use crate::{Conn, error::Error, schema::invites};
7
8/// Server invite struct
9#[derive(Clone, Serialize, Queryable, Selectable, Insertable)]
10pub struct Invite {
11    /// case-sensitive alphanumeric string with a fixed length of 8 characters, can be up to 32 characters for custom invites
12    pub id: String,
13    /// User that created the invite
14    pub user_uuid: Uuid,
15    /// UUID of the guild that the invite belongs to
16    pub guild_uuid: Uuid,
17}
18
19impl Invite {
20    pub async fn fetch_one(conn: &mut Conn, invite_id: String) -> Result<Self, Error> {
21        use invites::dsl;
22        let invite: Invite = dsl::invites
23            .filter(dsl::id.eq(invite_id))
24            .select(Invite::as_select())
25            .get_result(conn)
26            .await?;
27
28        Ok(invite)
29    }
30}