Code formatting
This commit is contained in:
@@ -27,4 +27,3 @@ impl Service {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-44
@@ -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) => match parse_token_response(&val).await {
|
||||||
Ok(val) => {
|
Ok(login_result) => Ok(login_result),
|
||||||
match parse_token_response(&val).await {
|
Err(err) => Err(err),
|
||||||
Ok(login_result) => Ok(login_result),
|
},
|
||||||
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) => match parse_token_response(&val).await {
|
||||||
Ok(val) => {
|
Ok(login_result) => Ok(login_result),
|
||||||
match parse_token_response(&val).await {
|
Err(err) => Err(err),
|
||||||
Ok(login_result) => Ok(login_result),
|
},
|
||||||
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,22 +85,20 @@ 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 =
|
||||||
Err(err) => {
|
match serde_json::from_value(lr) {
|
||||||
return Err(std::io::Error::other(err.to_string()));
|
Ok(lr) => lr,
|
||||||
}
|
Err(err) => {
|
||||||
};
|
return Err(std::io::Error::other(err.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
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())),
|
||||||
|
|||||||
Reference in New Issue
Block a user