2018-12-09 15:55:36 +00:00
|
|
|
use actix::{Actor, SyncContext};
|
2019-03-09 18:03:09 -08:00
|
|
|
use chrono::{Local, NaiveDateTime};
|
2018-12-09 15:55:36 +00:00
|
|
|
use diesel::pg::PgConnection;
|
|
|
|
use diesel::r2d2::{ConnectionManager, Pool};
|
|
|
|
use std::convert::From;
|
2019-03-09 18:03:09 -08:00
|
|
|
use uuid::Uuid;
|
2018-12-09 15:55:36 +00:00
|
|
|
|
2019-03-09 18:03:09 -08:00
|
|
|
use schema::{invitations, users};
|
2018-12-09 15:55:36 +00:00
|
|
|
|
|
|
|
/// This is db executor actor. can be run in parallel
|
|
|
|
pub struct DbExecutor(pub Pool<ConnectionManager<PgConnection>>);
|
|
|
|
|
|
|
|
// Actors communicate exclusively by exchanging messages.
|
|
|
|
// The sending actor can optionally wait for the response.
|
|
|
|
// Actors are not referenced directly, but by means of addresses.
|
|
|
|
// Any rust type can be an actor, it only needs to implement the Actor trait.
|
|
|
|
impl Actor for DbExecutor {
|
|
|
|
type Context = SyncContext<Self>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
|
|
|
|
#[table_name = "users"]
|
|
|
|
pub struct User {
|
|
|
|
pub email: String,
|
|
|
|
pub password: String,
|
|
|
|
pub created_at: NaiveDateTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl User {
|
|
|
|
pub fn with_details(email: String, password: String) -> Self {
|
|
|
|
User {
|
|
|
|
email,
|
|
|
|
password,
|
|
|
|
created_at: Local::now().naive_local(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
|
|
|
|
#[table_name = "invitations"]
|
|
|
|
pub struct Invitation {
|
|
|
|
pub id: Uuid,
|
|
|
|
pub email: String,
|
|
|
|
pub expires_at: NaiveDateTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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 }
|
2018-12-09 15:55:36 +00:00
|
|
|
}
|
|
|
|
}
|