Delete song #67
+26
-4
@@ -10,14 +10,33 @@ pub struct Delete {
|
||||
pub api: models::api::Api,
|
||||
}
|
||||
|
||||
mod response {
|
||||
pub mod delete_song {
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct SongAndCoverArt {
|
||||
pub song: icarus_models::song::Song,
|
||||
pub coverart: icarus_models::coverart::CoverArt
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<SongAndCoverArt>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Delete {
|
||||
pub async fn delete_song(
|
||||
&mut self,
|
||||
token: &icarus_models::token::AccessToken,
|
||||
song: &icarus_models::song::Song,
|
||||
) -> Result<icarus_models::song::Song, std::io::Error> {
|
||||
self.api.endpoint = "song/data/delete".to_owned();
|
||||
let url = syncers::common::retrieve_url(&self.api, true, &song.id);
|
||||
self.api.endpoint = "api/v2/song".to_owned();
|
||||
// let url = syncers::common::retrieve_url(&self.api, true, &song.id);
|
||||
let url = format!("{}{}/{}", self.api.url, self.api.endpoint, song.id);
|
||||
println!("Url: {url:?}");
|
||||
|
||||
let client = reqwest::Client::builder().build().unwrap();
|
||||
let access_token = token.bearer_token();
|
||||
let response = client
|
||||
@@ -31,8 +50,11 @@ impl Delete {
|
||||
reqwest::StatusCode::OK => {
|
||||
println!("Success!");
|
||||
|
||||
match response.json::<icarus_models::song::Song>().await {
|
||||
Ok(sng) => Ok(sng),
|
||||
match response.json::<response::delete_song::Response>().await {
|
||||
Ok(resp) => {
|
||||
println!("Response message: {:?}", resp.message);
|
||||
Ok(resp.data[0].song.clone())
|
||||
}
|
||||
Err(er) => Err(std::io::Error::other(er.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user