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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::time::SystemTime;

use derive_more::{Display, FromStr};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Display, Hash, FromStr)]
pub struct ClientId(String);

impl ClientId {
    pub fn new(name: String) -> Self {
        Self(name)
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }
}

#[derive(Deserialize, Serialize, Clone, Debug, Display)]
pub struct CreateClientData {
    pub name: String,
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct CreatedClientData {
    pub id: ClientId,
    pub secret: String,
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Client {
    pub id: ClientId,
    pub name: String,
}

#[derive(Deserialize, Serialize, Clone, Debug, FromStr)]
pub struct CodeId(String);

impl CodeId {
    pub fn new(name: String) -> Self {
        Self(name)
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }
}

#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Code {
    pub id: CodeId,
    pub username: String,
    pub client_id: ClientId,
    pub redirect_uri: String,
    pub created_at: SystemTime,
}

#[derive(Deserialize, Serialize, Clone, Debug, Display, FromStr)]
pub struct TokenId(String);

impl TokenId {
    pub fn new(name: String) -> Self {
        Self(name)
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }
}

#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Token {
    pub id: TokenId,
    pub client_id: ClientId,
    pub username: String,
    pub created_at: SystemTime,
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct CreateTokenParams {
    pub code: Option<String>,
    pub redirect_uri: Option<String>,
    pub grant_type: Option<String>,
}