Code formatting
catapult PR / Check (pull_request) Successful in 2m28s
catapult PR / Rustfmt (pull_request) Successful in 34s
catapult PR / Clippy (pull_request) Failing after 40s

This commit is contained in:
2026-06-24 14:40:03 -04:00
parent 5ae1715fb4
commit 75116d649e
2 changed files with 38 additions and 45 deletions
-1
View File
@@ -27,4 +27,3 @@ impl Service {
); );
} }
} }
+22 -28
View File
@@ -1,6 +1,5 @@
pub mod core; pub mod core;
pub mod auth { pub mod auth {
pub struct Auth { pub struct Auth {
pub app: crate::app::App, pub app: crate::app::App,
@@ -22,28 +21,27 @@ pub mod auth {
println!("Payload: {payload:?}"); println!("Payload: {payload:?}");
match client.post(api_url).json(&payload).send().await { match client.post(api_url).json(&payload).send().await {
Ok(response) => { Ok(response) => match response.status() {
match response.status() {
reqwest::StatusCode::OK => { reqwest::StatusCode::OK => {
println!("Response: {response:?}"); println!("Response: {response:?}");
match response.text().await { match response.text().await {
Ok(val) => { Ok(val) => match parse_token_response(&val).await {
match parse_token_response(&val).await {
Ok(login_result) => Ok(login_result), Ok(login_result) => Ok(login_result),
Err(err) => Err(err) Err(err) => Err(err),
} },
}
Err(err) => Err(std::io::Error::other(err)), Err(err) => Err(std::io::Error::other(err)),
} }
} }
_ => Err(std::io::Error::other("Error getting token")), _ => Err(std::io::Error::other("Error getting token")),
} },
}
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(std::io::Error::other(err.to_string())),
} }
} }
pub async fn get_refresh_token(&self, login_result: &textsender_models::token::Login) -> Result<textsender_models::token::Login, std::io::Error> { pub async fn get_refresh_token(
&self,
login_result: &textsender_models::token::Login,
) -> Result<textsender_models::token::Login, std::io::Error> {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let endpoint = String::from("api/v1/token/refresh"); let endpoint = String::from("api/v1/token/refresh");
let api_url = format!("{}/{endpoint}", self.app.auth_url); let api_url = format!("{}/{endpoint}", self.app.auth_url);
@@ -55,29 +53,27 @@ pub mod auth {
}); });
match client.post(api_url).json(&payload).send().await { match client.post(api_url).json(&payload).send().await {
Ok(response) => { Ok(response) => match response.status() {
match response.status() {
reqwest::StatusCode::OK => { reqwest::StatusCode::OK => {
println!("Response: {response:?}"); println!("Response: {response:?}");
match response.text().await { match response.text().await {
Ok(val) => { Ok(val) => match parse_token_response(&val).await {
match parse_token_response(&val).await {
Ok(login_result) => Ok(login_result), Ok(login_result) => Ok(login_result),
Err(err) => Err(err) Err(err) => Err(err),
} },
}
Err(err) => Err(std::io::Error::other(err)), Err(err) => Err(std::io::Error::other(err)),
} }
} }
_ => Err(std::io::Error::other("Error getting token")), _ => Err(std::io::Error::other("Error getting token")),
} },
}
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(std::io::Error::other(err.to_string())),
} }
} }
} }
async fn parse_token_response(response: &String) -> Result<textsender_models::token::LoginResult, std::io::Error> { async fn parse_token_response(
response: &String,
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
match serde_json::from_str::<serde_json::Value>(response) { match serde_json::from_str::<serde_json::Value>(response) {
Ok(j) => { Ok(j) => {
println!("Good"); println!("Good");
@@ -89,12 +85,12 @@ pub mod auth {
match j.get("data") { match j.get("data") {
Some(serde_json::Value::Array(lrs)) => { Some(serde_json::Value::Array(lrs)) => {
if lrs.is_empty() { if lrs.is_empty() {
Err(std::io::Error::other( Err(std::io::Error::other("Error response is empty"))
"Error response is empty",
))
} else { } else {
let lr = lrs[0].clone(); let lr = lrs[0].clone();
let ll: textsender_models::token::LoginResult = match serde_json::from_value(lr) { Ok(lr) => lr, let ll: textsender_models::token::LoginResult =
match serde_json::from_value(lr) {
Ok(lr) => lr,
Err(err) => { Err(err) => {
return Err(std::io::Error::other(err.to_string())); return Err(std::io::Error::other(err.to_string()));
} }
@@ -102,9 +98,7 @@ pub mod auth {
Ok(ll) Ok(ll)
} }
} }
_ => Err(std::io::Error::other( _ => Err(std::io::Error::other("Error parsing response")),
"Error parsing response",
)),
} }
} }
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(std::io::Error::other(err.to_string())),