From e109789b1878d61872242c22bff3f768b01f87c0 Mon Sep 17 00:00:00 2001 From: KD Date: Sat, 30 Aug 2025 12:10:03 -0400 Subject: [PATCH] Retrieve songs (#66) * Able to retrieve songs * Updated readme * Removed unused import * Code formatting * Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/managers/commit_manager.rs | 5 +++-- src/syncers/common.rs | 2 +- src/syncers/retrieve_records.rs | 24 +++++++++++++++++++----- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8b6f27..1befee6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -479,7 +479,7 @@ dependencies = [ [[package]] name = "icarus-dm" -version = "0.6.6" +version = "0.6.7" dependencies = [ "futures", "http", diff --git a/Cargo.toml b/Cargo.toml index 4b42cd5..261a223 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus-dm" -version = "0.6.6" +version = "0.6.7" rust-version = "1.88" edition = "2024" diff --git a/README.md b/README.md index 996cbfc..064638d 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -ha https ### Retrieving Song in json ```Bash -icarus-dm retrieve -u spacecadet -p stellar40 -h https://icarus.com -rt songs +icarus-dm retrieve -u spacecadet -p stellar40 -h https://icarus.com -ha https://auth.icarus.com -rt songs ``` ### Deleting Song diff --git a/src/managers/commit_manager.rs b/src/managers/commit_manager.rs index a08c96f..1c787b5 100644 --- a/src/managers/commit_manager.rs +++ b/src/managers/commit_manager.rs @@ -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); diff --git a/src/syncers/common.rs b/src/syncers/common.rs index 2bc1873..095b39b 100644 --- a/src/syncers/common.rs +++ b/src/syncers/common.rs @@ -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 } diff --git a/src/syncers/retrieve_records.rs b/src/syncers/retrieve_records.rs index dc906b8..96752c0 100644 --- a/src/syncers/retrieve_records.rs +++ b/src/syncers/retrieve_records.rs @@ -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, + } + } +} + impl RetrieveRecords { pub async fn get_all_songs( &mut self, token: &icarus_models::token::AccessToken, ) -> Result, 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::>().await { - Ok(parsed) => Ok(parsed), + match response.json::().await { + Ok(parsed) => { + println!("Response message: {:?}", parsed.message); + Ok(parsed.data) + } Err(err) => Err(std::io::Error::other(err.to_string())), } }