Updated icarus_models (#44)

* Updated icarus_models

* Constants and url changes

* Refactoring

* Removed functions

* Fixing tests
This commit was merged in pull request #44.
This commit is contained in:
KD
2025-03-30 16:00:06 -04:00
committed by GitHub
parent 24e066d8d9
commit 219b95bb2f
9 changed files with 93 additions and 125 deletions
+14 -29
View File
@@ -3,6 +3,7 @@ use std::default::Default;
use reqwest;
use crate::models;
use crate::syncers;
#[derive(Clone, Debug)]
pub struct Delete {
@@ -24,7 +25,7 @@ impl Delete {
song: &icarus_models::song::Song,
) -> Result<icarus_models::song::Song, std::io::Error> {
self.api.endpoint = "song/data/delete".to_owned();
let url = self.retrieve_url(&song);
let url = syncers::common::retrieve_url(&self.api, true, song.id);
let client = reqwest::Client::builder().build().unwrap();
let access_token = token.bearer_token();
let response = client
@@ -33,39 +34,23 @@ impl Delete {
.send()
.await
.unwrap();
let mut sng = icarus_models::song::Song::default();
match response.status() {
reqwest::StatusCode::OK => {
println!("Success!");
let s = response.json::<icarus_models::song::Song>().await;
match s {
Ok(parsed) => {
sng = parsed;
}
Err(er) => {
println!("Error {:?}", er);
}
};
}
other => {
panic!("Issue occurred: {:?}", other);
match response.json::<icarus_models::song::Song>().await {
Ok(sng) => Ok(sng),
Err(er) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
er.to_string(),
)),
}
}
other => Err(std::io::Error::new(
std::io::ErrorKind::Other,
other.to_string(),
)),
}
return Ok(sng);
}
fn retrieve_url(&self, song: &icarus_models::song::Song) -> String {
let api = &self.api;
let mut url: String = String::from(&api.url);
url += &String::from("api/");
url += &String::from(&api.version);
url += &String::from("/");
url += &String::from(&api.endpoint);
url += &String::from("/");
url += &song.id.to_string();
return url;
}
}