Retrieve songs #66

Merged
kdeng00 merged 5 commits from retrieve_songs into icarus_v2_support 2025-08-30 12:10:03 -04:00
3 changed files with 23 additions and 7 deletions
Showing only changes of commit 6278a212c2 - Show all commits
+3 -2
View File
@@ -251,10 +251,11 @@ impl CommitManager {
let api = prsr.retrieve_api(parsers::api_parser::APIType::Main);
let mut repo = syncers::retrieve_records::RetrieveRecords { api: api.clone() };
let result_fut = repo.get_all_songs(&token);
match Runtime::new().unwrap().block_on(result_fut) {
match repo.get_all_songs(&token).await {
Ok(o) => {
println!("Songs");
println!("=====");
for song in o {
println!("Title: {:?}", song.title);
println!("Artist: {:?}", song.artist);
+1 -1
View File
@@ -9,7 +9,7 @@ pub fn retrieve_url(api: &models::api::Api, with_id: bool, id: &uuid::Uuid) -> S
}
fn retrieve_url_reg(api: &models::api::Api) -> String {
let url = format!("{}/api/{}/{}/", api.url, api.version, api.endpoint);
let url = format!("{}api/{}/{}/", api.url, api.version, api.endpoint);
url
}
+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())),
}
}