From b51551973ab598d2bbfcaf9a6b07cd06d3feae51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 27 Jan 2020 20:45:24 +0100 Subject: [PATCH] start fixing tests in plume-models --- plume-models/src/plume_rocket.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plume-models/src/plume_rocket.rs b/plume-models/src/plume_rocket.rs index 7e297d0f..358339ac 100644 --- a/plume-models/src/plume_rocket.rs +++ b/plume-models/src/plume_rocket.rs @@ -48,7 +48,7 @@ mod module { mod module { use crate::{db_conn::DbConn, search, users}; use rocket::{ - request::{self, FromRequest, Request}, + request::{self, FromRequestAsync, Request}, Outcome, State, }; use scheduled_thread_pool::ScheduledThreadPool; @@ -62,19 +62,21 @@ mod module { pub worker: Arc, } - impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket { + impl<'a, 'r> FromRequestAsync<'a, 'r> for PlumeRocket { type Error = (); - fn from_request(request: &'a Request<'r>) -> request::Outcome { - let conn = DbConn::from_request(request).await; - let user = request.guard::().succeeded(); - let worker = request.guard::<'_, State<'_, Arc>>()?; - let searcher = request.guard::<'_, State<'_, Arc>>()?; - Outcome::Success(PlumeRocket { - conn, - user, - worker: worker.clone(), - searcher: searcher.clone(), + fn from_request(request: &'a Request<'r>) -> request::FromRequestFuture<'a, Self, Self::Error> { + Box::pin(async move { + let conn = try_outcome!(DbConn::from_request(request).await); + let user = try_outcome!(users::User::from_request(request).await); + let worker = try_outcome!(request.guard::<'_, State<'_, Arc>>()); + let searcher = try_outcome!(request.guard::<'_, State<'_, Arc>>()); + Outcome::Success(PlumeRocket { + conn, + user: Some(user), + worker: worker.clone(), + searcher: searcher.clone(), + }) }) } }