use actix::{Actor, SyncContext}; use chrono::{Local, NaiveDateTime}; use diesel::pg::PgConnection; use diesel::r2d2::{ConnectionManager, Pool}; use std::convert::From; use uuid::Uuid; use crate::schema::{invitations, users}; /// This is db executor actor. can be run in parallel pub struct DbExecutor(pub Pool>); // 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; } #[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 for SlimUser { fn from(user: User) -> Self { SlimUser { email: user.email } } }