2019-03-29 13:43:03 -07:00
|
|
|
use actix::Addr;
|
|
|
|
use actix_web::{web, Error, HttpResponse, ResponseError};
|
2018-12-09 15:55:36 +00:00
|
|
|
use futures::future::Future;
|
|
|
|
|
2019-03-29 13:43:03 -07:00
|
|
|
use crate::email_service::send_invitation;
|
|
|
|
use crate::invitation_handler::CreateInvitation;
|
|
|
|
use crate::models::DbExecutor;
|
2018-12-09 15:55:36 +00:00
|
|
|
|
|
|
|
pub fn register_email(
|
2019-03-29 13:43:03 -07:00
|
|
|
signup_invitation: web::Json<CreateInvitation>,
|
|
|
|
db: web::Data<Addr<DbExecutor>>,
|
|
|
|
) -> impl Future<Item = HttpResponse, Error = Error> {
|
|
|
|
db.send(signup_invitation.into_inner())
|
2018-12-09 15:55:36 +00:00
|
|
|
.from_err()
|
|
|
|
.and_then(|db_response| match db_response {
|
|
|
|
Ok(invitation) => {
|
|
|
|
send_invitation(&invitation);
|
|
|
|
Ok(HttpResponse::Ok().into())
|
|
|
|
}
|
|
|
|
Err(err) => Ok(err.error_response()),
|
2019-03-09 18:03:09 -08:00
|
|
|
})
|
2018-12-09 15:55:36 +00:00
|
|
|
}
|