Able to retrieve songs

This commit is contained in:
kdeng00
2025-08-30 12:03:26 -04:00
parent ec0cbd7da0
commit 6278a212c2
3 changed files with 23 additions and 7 deletions
+19 -4
View File
@@ -9,15 +9,27 @@ pub struct RetrieveRecords {
pub api: models::api::Api,
}
mod response {
pub mod get_all_songs {
#[derive(Debug, serde::Deserialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>
}
}
}
impl RetrieveRecords {
pub async fn get_all_songs(
&mut self,
token: &icarus_models::token::AccessToken,
) -> Result<Vec<icarus_models::song::Song>, Error> {
self.api.endpoint = String::from("song");
let url = syncers::common::retrieve_url(&self.api, false, &uuid::Uuid::nil());
self.api.endpoint = String::from("api/v2/song/all");
let url = format!("{}{}", self.api.url, self.api.endpoint);
let access_token = token.bearer_token();
println!("url: {url:?}");
let client = reqwest::Client::builder().build().unwrap();
let response = client
.get(&url)
@@ -29,8 +41,11 @@ impl RetrieveRecords {
match response.status() {
reqwest::StatusCode::OK => {
// on success, parse our JSON to an API Response
match response.json::<Vec<icarus_models::song::Song>>().await {
Ok(parsed) => Ok(parsed),
match response.json::<response::get_all_songs::Response>().await {
Ok(parsed) => {
println!("Response message: {:?}", parsed.message);
Ok(parsed.data)
}
Err(err) => Err(std::io::Error::other(err.to_string())),
}
}