use super::schema::*; use diesel::{r2d2::ConnectionManager, PgConnection}; // type alias to use in multiple places pub type Pool = r2d2::Pool>; #[derive(Debug, Serialize, Deserialize, Queryable, Insertable)] #[table_name = "users"] pub struct User { pub email: String, pub hash: String, pub created_at: chrono::NaiveDateTime, } impl User { pub fn from_details, T: Into>(email: S, pwd: T) -> Self { User { email: email.into(), hash: pwd.into(), created_at: chrono::Local::now().naive_local(), } } } #[derive(Debug, Serialize, Deserialize, Queryable, Insertable)] #[table_name = "invitations"] pub struct Invitation { pub id: uuid::Uuid, pub email: String, pub expires_at: chrono::NaiveDateTime, } // any type that implements Into can be used to create Invitation impl From for Invitation where T: Into, { fn from(email: T) -> Self { Invitation { id: uuid::Uuid::new_v4(), email: email.into(), expires_at: chrono::Local::now().naive_local() + chrono::Duration::hours(24), } } } #[derive(Debug, Serialize, Deserialize)] pub struct SlimUser { pub email: String, } impl From for SlimUser { fn from(user: User) -> Self { SlimUser { email: user.email } } }