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, setup::app::Setup, token::{self, app::Tokens}, vapid::app::Vapid, }; #[derive(Clone)] pub struct App { db: SqlitePool, events: event::Broadcaster, token_events: token::Broadcaster, } impl App { pub fn from(db: SqlitePool) -> Self { let events = event::Broadcaster::default(); let token_events = token::Broadcaster::default(); Self { db, events, token_events, } } } impl App { pub const fn boot(&self) -> Boot<'_> { Boot::new(&self.db) } pub const fn conversations(&self) -> Conversations<'_> { Conversations::new(&self.db, &self.events) } pub const fn events(&self) -> Events<'_> { Events::new(&self.db, &self.events) } pub const fn invites(&self) -> Invites<'_> { Invites::new(&self.db, &self.events) } pub const fn logins(&self) -> Logins<'_> { Logins::new(&self.db, &self.token_events) } pub const fn messages(&self) -> Messages<'_> { Messages::new(&self.db, &self.events) } pub const fn setup(&self) -> Setup<'_> { Setup::new(&self.db, &self.events) } pub const fn tokens(&self) -> Tokens<'_> { Tokens::new(&self.db, &self.token_events) } #[cfg(test)] pub const fn users(&self) -> Users<'_> { Users::new(&self.db, &self.events) } pub const fn vapid(&self) -> Vapid<'_> { Vapid::new(&self.db, &self.events) } }