1
0
mirror of https://github.com/actix/examples synced 2025-02-02 17:39:05 +01:00

61 lines
1.5 KiB
Rust
Raw Normal View History

2022-07-09 23:39:21 +01:00
#![allow(clippy::extra_unused_lifetimes)]
use diesel::{r2d2::ConnectionManager, PgConnection};
use serde::{Deserialize, Serialize};
2022-07-09 21:08:11 +01:00
use super::schema::*;
// type alias to use in multiple places
pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
2022-09-10 23:33:09 +01:00
#[diesel(table_name = users)]
pub struct User {
pub email: String,
pub hash: String,
pub created_at: chrono::NaiveDateTime,
}
impl User {
pub fn from_details<S: Into<String>, T: Into<String>>(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)]
2022-09-10 23:33:09 +01:00
#[diesel(table_name = invitations)]
pub struct Invitation {
pub id: uuid::Uuid,
pub email: String,
pub expires_at: chrono::NaiveDateTime,
}
// any type that implements Into<String> can be used to create Invitation
2019-07-18 18:03:19 +06:00
impl<T> From<T> for Invitation
where
T: Into<String>,
{
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<User> for SlimUser {
fn from(user: User) -> Self {
2019-03-09 18:03:09 -08:00
SlimUser { email: user.email }
}
}