Remove DbConn from PlumeRocket
This commit is contained in:
parent
0dc89fbf23
commit
5d25a64f13
@ -2,7 +2,7 @@ pub use self::module::PlumeRocket;
|
|||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
mod module {
|
mod module {
|
||||||
use crate::{db_conn::DbConn, search, users};
|
use crate::{search, users};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
request::{self, FlashMessage, FromRequest, Request},
|
request::{self, FlashMessage, FromRequest, Request},
|
||||||
Outcome, State,
|
Outcome, State,
|
||||||
@ -12,7 +12,6 @@ mod module {
|
|||||||
|
|
||||||
/// Common context needed by most routes and operations on models
|
/// Common context needed by most routes and operations on models
|
||||||
pub struct PlumeRocket {
|
pub struct PlumeRocket {
|
||||||
pub conn: DbConn,
|
|
||||||
pub intl: rocket_i18n::I18n,
|
pub intl: rocket_i18n::I18n,
|
||||||
pub user: Option<users::User>,
|
pub user: Option<users::User>,
|
||||||
pub searcher: Arc<search::Searcher>,
|
pub searcher: Arc<search::Searcher>,
|
||||||
@ -24,14 +23,12 @@ mod module {
|
|||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
||||||
let conn = request.guard::<DbConn>()?;
|
|
||||||
let intl = request.guard::<rocket_i18n::I18n>()?;
|
let intl = request.guard::<rocket_i18n::I18n>()?;
|
||||||
let user = request.guard::<users::User>().succeeded();
|
let user = request.guard::<users::User>().succeeded();
|
||||||
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
||||||
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
||||||
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
|
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
|
||||||
Outcome::Success(PlumeRocket {
|
Outcome::Success(PlumeRocket {
|
||||||
conn,
|
|
||||||
intl,
|
intl,
|
||||||
user,
|
user,
|
||||||
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
|
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
|
||||||
@ -44,7 +41,7 @@ mod module {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod module {
|
mod module {
|
||||||
use crate::{db_conn::DbConn, search, users};
|
use crate::{search, users};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
request::{self, FromRequest, Request},
|
request::{self, FromRequest, Request},
|
||||||
Outcome, State,
|
Outcome, State,
|
||||||
@ -54,7 +51,6 @@ mod module {
|
|||||||
|
|
||||||
/// Common context needed by most routes and operations on models
|
/// Common context needed by most routes and operations on models
|
||||||
pub struct PlumeRocket {
|
pub struct PlumeRocket {
|
||||||
pub conn: DbConn,
|
|
||||||
pub user: Option<users::User>,
|
pub user: Option<users::User>,
|
||||||
pub searcher: Arc<search::Searcher>,
|
pub searcher: Arc<search::Searcher>,
|
||||||
pub worker: Arc<ScheduledThreadPool>,
|
pub worker: Arc<ScheduledThreadPool>,
|
||||||
@ -64,12 +60,10 @@ mod module {
|
|||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
||||||
let conn = request.guard::<DbConn>()?;
|
|
||||||
let user = request.guard::<users::User>().succeeded();
|
let user = request.guard::<users::User>().succeeded();
|
||||||
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
||||||
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
||||||
Outcome::Success(PlumeRocket {
|
Outcome::Success(PlumeRocket {
|
||||||
conn,
|
|
||||||
user,
|
user,
|
||||||
worker: worker.clone(),
|
worker: worker.clone(),
|
||||||
searcher: searcher.clone(),
|
searcher: searcher.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user