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