rusty-bever/src/rb/models.rs

40 lines
887 B
Rust
Raw Normal View History

2021-08-21 18:05:16 +02:00
use crate::schema::{refresh_tokens, users};
2021-08-21 21:42:36 +02:00
use diesel::{AsChangeset, Insertable, Queryable};
2021-08-21 13:46:41 +02:00
use serde::Serialize;
2021-08-21 18:05:16 +02:00
use uuid::Uuid;
2021-08-20 23:09:22 +02:00
2021-08-21 13:46:41 +02:00
#[derive(Queryable, Serialize)]
2021-08-20 23:09:22 +02:00
pub struct User {
2021-08-21 13:46:41 +02:00
pub id: Uuid,
pub username: String,
#[serde(skip_serializing)]
2021-08-20 23:09:22 +02:00
pub password: String,
2021-08-21 13:46:41 +02:00
#[serde(skip_serializing)]
2021-08-21 18:05:16 +02:00
pub blocked: bool,
2021-08-21 16:45:41 +02:00
pub admin: bool,
}
2021-08-21 18:05:16 +02:00
#[derive(Insertable, AsChangeset)]
#[table_name = "users"]
pub struct NewUser {
pub username: String,
pub password: String,
pub admin: bool,
}
2021-08-21 16:45:41 +02:00
2021-08-22 10:42:58 +02:00
#[derive(Queryable)]
pub struct RefreshToken {
pub token: Vec<u8>,
pub user_id: Uuid,
pub expires_at: chrono::NaiveDateTime,
pub last_used_at: Option<chrono::NaiveDateTime>,
}
2021-08-21 16:45:41 +02:00
#[derive(Insertable)]
#[table_name = "refresh_tokens"]
pub struct NewRefreshToken {
pub token: Vec<u8>,
2021-08-21 18:05:16 +02:00
pub user_id: Uuid,
2021-08-21 21:42:36 +02:00
pub expires_at: chrono::NaiveDateTime,
2021-08-20 23:09:22 +02:00
}