summaryrefslogtreecommitdiff
path: root/src/models.rs
blob: ce3dd19496440a7b02fe78ead8ad26dba5bbaf24 (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
use crate::schema::config;
use crate::schema::strava_tokens;
use crate::schema::users;
use chrono::DateTime;
use chrono::Utc;
use std::fmt;

#[derive(Insertable, Queryable)]
#[table_name = "config"]
pub struct Config {
    pub strava_client_secret: String,
    pub strava_client_id: String,
    pub rocket_secret_key: String,
    pub singleton: bool,
}

#[derive(Insertable)]
#[table_name = "users"]
pub struct NewUser<'a> {
    pub username: &'a str,
    pub password: &'a str,
}

#[derive(Queryable, Clone)]
pub struct User {
    pub username: String,
    pub password: String,
}

impl fmt::Debug for User {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "User {{ username: {}, password: <secret> }}",
            self.username
        )
    }
}

#[derive(Insertable, Queryable)]
#[table_name = "strava_tokens"]
pub struct StravaToken {
    pub username: String,
    pub refresh_token: String,
    pub access_token: String,
    pub expires_at: DateTime<Utc>,
}