Refactoring #15

Merged
phoenix merged 4 commits from refactoring into main 2026-07-07 15:51:07 -04:00
9 changed files with 37 additions and 33 deletions
Showing only changes of commit 96fd175465 - Show all commits
+10 -6
View File
@@ -7,7 +7,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
let app = match catapult::app::load_app() {
Ok(app) => app,
Ok(app) => std::sync::Arc::new(app),
Err(err) => {
eprintln!("Error: {err:?}");
std::process::exit(-1);
@@ -16,9 +16,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("App: {app:?}");
let auth = catapult::service::auth::Auth { app: app.clone() };
// let auth = catapult::service::auth::Auth { app: app.clone() };
let auth = catapult::service::auth::Auth {
app: std::sync::Arc::clone(&app),
};
let token = match auth.get_token().await {
Ok(token) => token,
Ok(token) => std::sync::Arc::new(token),
Err(err) => {
eprintln!("Error getting token");
eprintln!("Error: {err:?}");
@@ -27,8 +30,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let mut svc = catapult::service::core::Service {
app: app.clone(),
token,
app: std::sync::Arc::clone(&app),
token: std::sync::Arc::clone(&token),
};
loop {
@@ -36,7 +39,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match auth.get_refresh_token(&svc.token).await {
Ok(refresh) => {
println!("Refresh token: {refresh:?}");
svc.token = refresh;
let refreshed = std::sync::Arc::new(refresh);
svc.token = refreshed;
}
Err(err) => {
eprintln!("Error: {err:?}");
+1 -1
View File
@@ -1,5 +1,5 @@
pub struct Auth {
pub app: crate::app::App,
pub app: std::sync::Arc<crate::app::App>,
}
impl Auth {
+2 -2
View File
@@ -1,6 +1,6 @@
pub struct Contact {
pub app: crate::app::App,
pub token: textsender_models::token::LoginResult,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::LoginResult>,
}
impl Contact {
+14 -14
View File
@@ -1,6 +1,6 @@
pub struct Service {
pub app: crate::app::App,
pub token: textsender_models::token::Login,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::Login>,
}
impl Service {
@@ -10,8 +10,8 @@ impl Service {
use textsender_models::message::scheduling::ScheduledMessage;
let queue = super::queue::Queue {
app: self.app.clone(),
token: self.token.clone(),
app: std::sync::Arc::clone(&self.app),
token: std::sync::Arc::clone(&self.token),
};
let queue_item: Option<ScheduledMessage> = match queue.get_queue().await {
Ok(item) => Some(item),
@@ -37,8 +37,8 @@ impl Service {
println!("Can schedule");
let events_req = super::event::Event {
app: self.app.clone(),
token: self.token.clone(),
app: std::sync::Arc::clone(&self.app),
token: std::sync::Arc::clone(&self.token),
};
let scheduled_message_id = queue_item.id;
@@ -51,20 +51,20 @@ impl Service {
};
let contacts = super::contact::Contact {
app: self.app.clone(),
token: self.token.clone(),
app: std::sync::Arc::clone(&self.app),
token: std::sync::Arc::clone(&self.token),
};
let messages = super::message::Message {
app: self.app.clone(),
token: self.token.clone(),
app: std::sync::Arc::clone(&self.app),
token: std::sync::Arc::clone(&self.token),
};
let sch_msg = super::scheduler::ScheduledMessage {
app: self.app.clone(),
token: self.token.clone(),
app: std::sync::Arc::clone(&self.app),
token: std::sync::Arc::clone(&self.token),
};
let mer_req = super::mer::MessageEventResponse {
app: self.app.clone(),
token: self.token.clone(),
app: std::sync::Arc::clone(&self.app),
token: std::sync::Arc::clone(&self.token),
};
let events = events.unwrap_or_default();
+2 -2
View File
@@ -1,6 +1,6 @@
pub struct Event {
pub app: crate::app::App,
pub token: textsender_models::token::LoginResult,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::LoginResult>,
}
impl Event {
+2 -2
View File
@@ -1,6 +1,6 @@
pub struct MessageEventResponse {
pub app: crate::app::App,
pub token: textsender_models::token::LoginResult,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::LoginResult>,
}
impl MessageEventResponse {
+2 -2
View File
@@ -1,6 +1,6 @@
pub struct Message {
pub app: crate::app::App,
pub token: textsender_models::token::LoginResult,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::LoginResult>,
}
impl Message {
+2 -2
View File
@@ -1,6 +1,6 @@
pub struct Queue {
pub app: crate::app::App,
pub token: textsender_models::token::LoginResult,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::LoginResult>,
}
impl Queue {
+2 -2
View File
@@ -1,6 +1,6 @@
pub struct ScheduledMessage {
pub app: crate::app::App,
pub token: textsender_models::token::LoginResult,
pub app: std::sync::Arc<crate::app::App>,
pub token: std::sync::Arc<textsender_models::token::LoginResult>,
}
impl ScheduledMessage {