use axum::extract::FromRef; use sqlx::sqlite::SqlitePool; #[cfg(test)] use crate::user::app::Users; use crate::{ boot::app::Boot, conversation::app::Conversations, event::{self, app::Events}, invite::app::Invites, login::app::Logins, message::app::Messages, push::app::Push, setup::app::Setup, token::{self, app::Tokens}, vapid::app::Vapid, }; #[derive(Clone)] pub struct App

{ db: SqlitePool, webpush: P, events: event::Broadcaster, token_events: token::Broadcaster, } impl

App

{ pub fn from(db: SqlitePool, webpush: P) -> Self { let events = event::Broadcaster::default(); let token_events = token::Broadcaster::default(); Self { db, webpush, events, token_events, } } } impl

App

{ pub fn boot(&self) -> Boot { Boot::new(self.db.clone()) } pub fn conversations(&self) -> Conversations { Conversations::new(self.db.clone(), self.events.clone()) } pub fn events(&self) -> Events { Events::new(self.db.clone(), self.events.clone()) } pub fn invites(&self) -> Invites { Invites::new(self.db.clone(), self.events.clone()) } pub fn logins(&self) -> Logins { Logins::new(self.db.clone(), self.token_events.clone()) } pub fn messages(&self) -> Messages { Messages::new(self.db.clone(), self.events.clone()) } pub fn push(&self) -> Push

where P: Clone, { Push::new(self.db.clone(), self.webpush.clone()) } pub fn setup(&self) -> Setup { Setup::new(self.db.clone(), self.events.clone()) } pub fn tokens(&self) -> Tokens { Tokens::new(self.db.clone(), self.token_events.clone()) } #[cfg(test)] pub fn users(&self) -> Users { Users::new(self.db.clone(), self.events.clone()) } pub fn vapid(&self) -> Vapid { Vapid::new(self.db.clone(), self.events.clone()) } #[cfg(test)] pub fn webpush(&self) -> &P { &self.webpush } } impl

FromRef> for Boot { fn from_ref(app: &App

) -> Self { app.boot() } } impl

FromRef> for Conversations { fn from_ref(app: &App

) -> Self { app.conversations() } } impl

FromRef> for Invites { fn from_ref(app: &App

) -> Self { app.invites() } } impl

FromRef> for Logins { fn from_ref(app: &App

) -> Self { app.logins() } } impl

FromRef> for Messages { fn from_ref(app: &App

) -> Self { app.messages() } } impl

FromRef> for Push

where P: Clone, { fn from_ref(app: &App

) -> Self { app.push() } } impl

FromRef> for Setup { fn from_ref(app: &App

) -> Self { app.setup() } } impl

FromRef> for Tokens { fn from_ref(app: &App

) -> Self { app.tokens() } } impl

FromRef> for Vapid { fn from_ref(app: &App

) -> Self { app.vapid() } }