Retrieve songs (#66)

* Able to retrieve songs

* Updated readme

* Removed unused import

* Code formatting

* Version bump
This commit was merged in pull request #66.
This commit is contained in:
KD
2025-08-30 12:10:03 -04:00
committed by GitHub
parent ec0cbd7da0
commit e109789b18
6 changed files with 26 additions and 11 deletions
+19 -5
View File
@@ -2,22 +2,33 @@ use std::default::Default;
use std::io::Error;
use crate::models;
use crate::syncers;
#[derive(Default)]
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 +40,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())),
}
}