Able to get events
This commit is contained in:
+32
-32
@@ -7,9 +7,11 @@ impl Event {
|
||||
pub async fn get(
|
||||
&self,
|
||||
scheduled_message_id: &uuid::Uuid,
|
||||
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error> {
|
||||
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error>
|
||||
{
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = format!("api/v1/schedule/message/event?scheduled_message_id={scheduled_message_id}");
|
||||
let endpoint =
|
||||
format!("api/v1/schedule/message/event?scheduled_message_id={scheduled_message_id}");
|
||||
let api_url = format!("{}/{endpoint}", self.app.api_url);
|
||||
|
||||
println!("Url: {api_url:?}");
|
||||
@@ -18,15 +20,13 @@ impl Event {
|
||||
|
||||
match client.get(api_url).header(key, header).send().await {
|
||||
Ok(response) => match response.status() {
|
||||
reqwest::StatusCode::OK => {
|
||||
match response.text().await {
|
||||
Ok(val) => match parse_response(&val).await {
|
||||
Ok(login_result) => Ok(login_result),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err)),
|
||||
}
|
||||
}
|
||||
reqwest::StatusCode::OK => match response.text().await {
|
||||
Ok(val) => match parse_response(&val).await {
|
||||
Ok(login_result) => Ok(login_result),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err)),
|
||||
},
|
||||
_ => Err(std::io::Error::other("Error getting token")),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
@@ -38,31 +38,31 @@ async fn parse_response(
|
||||
response: &str,
|
||||
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error> {
|
||||
match serde_json::from_str::<serde_json::Value>(response) {
|
||||
Ok(j) => {
|
||||
match j.get("data") {
|
||||
Some(serde_json::Value::Array(lrs)) => {
|
||||
if lrs.is_empty() {
|
||||
Err(std::io::Error::other("Error response is empty"))
|
||||
} else {
|
||||
let mut events: Vec<textsender_models::message::scheduling::ScheduledMessageEvent> = Vec::new();
|
||||
Ok(j) => match j.get("data") {
|
||||
Some(serde_json::Value::Array(lrs)) => {
|
||||
if lrs.is_empty() {
|
||||
Err(std::io::Error::other("Error response is empty"))
|
||||
} else {
|
||||
let mut events: Vec<
|
||||
textsender_models::message::scheduling::ScheduledMessageEvent,
|
||||
> = Vec::new();
|
||||
|
||||
for event in lrs.iter() {
|
||||
let ll: textsender_models::message::scheduling::ScheduledMessageEvent =
|
||||
match serde_json::from_value(event.clone()) {
|
||||
Ok(lr) => lr,
|
||||
Err(err) => {
|
||||
return Err(std::io::Error::other(err.to_string()));
|
||||
}
|
||||
};
|
||||
events.push(ll);
|
||||
}
|
||||
|
||||
Ok(events)
|
||||
for event in lrs.iter() {
|
||||
let ll: textsender_models::message::scheduling::ScheduledMessageEvent =
|
||||
match serde_json::from_value(event.clone()) {
|
||||
Ok(lr) => lr,
|
||||
Err(err) => {
|
||||
return Err(std::io::Error::other(err.to_string()));
|
||||
}
|
||||
};
|
||||
events.push(ll);
|
||||
}
|
||||
|
||||
Ok(events)
|
||||
}
|
||||
_ => Err(std::io::Error::other("Error parsing response")),
|
||||
}
|
||||
}
|
||||
_ => Err(std::io::Error::other("Error parsing response")),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user