Code cleanup
This commit is contained in:
+12
-47
@@ -81,21 +81,21 @@ pub mod endpoint {
|
|||||||
match message_repo::get(&pool, &payload.message_id).await {
|
match message_repo::get(&pool, &payload.message_id).await {
|
||||||
Ok(message) => {
|
Ok(message) => {
|
||||||
println!("Valid message");
|
println!("Valid message");
|
||||||
let t_config = match load_config().await {
|
let t_config =
|
||||||
Ok(config) => config,
|
match textsender_models::config::auxiliary::load_config().await {
|
||||||
Err(err) => {
|
Ok(config) => config,
|
||||||
eprintln!("Error: {err:?}");
|
Err(err) => {
|
||||||
response.message = String::from("Error getting config");
|
eprintln!("Error: {err:?}");
|
||||||
return (
|
response.message = String::from("Error getting config");
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
return (
|
||||||
axum::Json(response),
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
);
|
axum::Json(response),
|
||||||
}
|
);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
let mut results: Vec<
|
let mut results: Vec<
|
||||||
textsender_models::message::event::MessageEventResponse,
|
textsender_models::message::event::MessageEventResponse,
|
||||||
> = Vec::new();
|
> = Vec::new();
|
||||||
// let mut results: Vec<serde_json::Value> = Vec::new();
|
|
||||||
let pp = swoosh::twilio::types::Parameters {
|
let pp = swoosh::twilio::types::Parameters {
|
||||||
schedule: false,
|
schedule: false,
|
||||||
schedule_at: None,
|
schedule_at: None,
|
||||||
@@ -108,9 +108,7 @@ pub mod endpoint {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
println!("Response: {result:?}");
|
|
||||||
let val = swoosh::twilio::api::response_to_json(result).await;
|
let val = swoosh::twilio::api::response_to_json(result).await;
|
||||||
// results.push(val);
|
|
||||||
let mer = textsender_models::message::event::MessageEventResponse {
|
let mer = textsender_models::message::event::MessageEventResponse {
|
||||||
user_id: payload.user_id,
|
user_id: payload.user_id,
|
||||||
// TODO: Make this more accurate
|
// TODO: Make this more accurate
|
||||||
@@ -170,37 +168,4 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_config()
|
|
||||||
-> Result<textsender_models::config::auxiliary::TwilioConfig, std::io::Error> {
|
|
||||||
let mut config = textsender_models::config::auxiliary::TwilioConfig {
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let auth_sid_var = textsender_models::envy::environment::get_env("TWILIO_AUTH_SID").await;
|
|
||||||
println!("{auth_sid_var:?}");
|
|
||||||
let service_sid_var =
|
|
||||||
textsender_models::envy::environment::get_env("TWILIO_SERVICE_SID").await;
|
|
||||||
println!("{service_sid_var:?}");
|
|
||||||
let auth_token_var =
|
|
||||||
textsender_models::envy::environment::get_env("TWILIO_AUTH_TOKEN").await;
|
|
||||||
println!("{auth_token_var:?}");
|
|
||||||
let phone_number_var =
|
|
||||||
textsender_models::envy::environment::get_env("TWILIO_PHONE_NUMBER").await;
|
|
||||||
println!("{phone_number_var:?}");
|
|
||||||
|
|
||||||
if auth_sid_var.value.is_empty()
|
|
||||||
|| service_sid_var.value.is_empty()
|
|
||||||
|| auth_token_var.value.is_empty()
|
|
||||||
|| phone_number_var.value.is_empty()
|
|
||||||
{
|
|
||||||
Err(std::io::Error::other("Config not set"))
|
|
||||||
} else {
|
|
||||||
config.account_sid = auth_sid_var.value;
|
|
||||||
config.service_sid = service_sid_var.value;
|
|
||||||
config.auth_token = auth_token_var.value;
|
|
||||||
config.phone_number = phone_number_var.value;
|
|
||||||
Ok(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user