aboutsummaryrefslogtreecommitdiff
path: root/src/models.rs
blob: e815b7376b1c839baddafc03265dd2d6b2e59196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use chrono::NaiveDateTime;
use entity::{invite_tokens, queues, users};
use serde::Serialize;
use utoipa::ToSchema;
use uuid::Uuid;

#[derive(Serialize, ToSchema)]
#[schema(description = "Account information")]
pub struct Account {
    #[schema(examples(1))]
    pub id: i64,
    #[schema(examples("john_doe", "ivanov_ivan"))]
    pub username: String,
    #[schema(examples("John", "Иван"))]
    pub first_name: String,
    #[schema(examples("Doe", "Иванов"))]
    pub last_name: String,
}

impl From<users::Model> for Account {
    fn from(value: users::Model) -> Self {
        Self {
            id: value.id,
            username: value.username,
            first_name: value.first_name,
            last_name: value.last_name,
        }
    }
}

#[derive(Serialize, ToSchema)]
pub struct Queue {
    #[schema(examples(1))]
    pub id: i64,
    #[schema(examples("John's queue", "Очередь Ивана"))]
    pub name: String,
}

impl From<queues::Model> for Queue {
    fn from(value: queues::Model) -> Self {
        Self {
            id: value.id,
            name: value.name,
        }
    }
}

#[derive(Serialize, ToSchema)]
pub struct InviteToken {
    #[schema(examples(1))]
    pub id: i64,
    pub token: Uuid,
    #[schema(examples(1))]
    pub queue_id: i64,
    #[schema(examples("For classmates", "Для однокурсников"))]
    pub name: String,
    #[schema(examples(false))]
    pub expiration_date: Option<NaiveDateTime>,
}

impl From<invite_tokens::Model> for InviteToken {
    fn from(value: invite_tokens::Model) -> Self {
        Self {
            id: value.id,
            token: value.token,
            queue_id: value.queue_id,
            name: value.name,
            expiration_date: value.expiration_date,
        }
    }
}