1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
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,
setup::app::Setup,
token::{self, app::Tokens},
};
#[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 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 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)
}
}
impl FromRef<App> for Boot {
fn from_ref(app: &App) -> Self {
app.boot()
}
}
impl FromRef<App> for Conversations {
fn from_ref(app: &App) -> Self {
app.conversations()
}
}
|