start fixing tests in plume-models

This commit is contained in:
Igor Galić 2020-01-27 20:45:24 +01:00
parent 59e5c49aa8
commit b51551973a
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86

View File

@ -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,20 +62,22 @@ mod module {
pub worker: Arc<ScheduledThreadPool>,
}
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<PlumeRocket, ()> {
let conn = DbConn::from_request(request).await;
let user = request.guard::<users::User>().succeeded();
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
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<ScheduledThreadPool>>>());
let searcher = try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
Outcome::Success(PlumeRocket {
conn,
user,
user: Some(user),
worker: worker.clone(),
searcher: searcher.clone(),
})
})
}
}
}