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
+3 -2
View File
@@ -251,10 +251,11 @@ impl CommitManager {
let api = prsr.retrieve_api(parsers::api_parser::APIType::Main); let api = prsr.retrieve_api(parsers::api_parser::APIType::Main);
let mut repo = syncers::retrieve_records::RetrieveRecords { api: api.clone() }; 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) => { Ok(o) => {
println!("Songs");
println!("=====");
for song in o { for song in o {
println!("Title: {:?}", song.title); println!("Title: {:?}", song.title);
println!("Artist: {:?}", song.artist); 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 { 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 url
} }
+19 -4
View File
@@ -9,15 +9,27 @@ pub struct RetrieveRecords {
pub api: models::api::Api, 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 { impl RetrieveRecords {
pub async fn get_all_songs( pub async fn get_all_songs(
&mut self, &mut self,
token: &icarus_models::token::AccessToken, token: &icarus_models::token::AccessToken,
) -> Result<Vec<icarus_models::song::Song>, Error> { ) -> Result<Vec<icarus_models::song::Song>, Error> {
self.api.endpoint = String::from("song"); self.api.endpoint = String::from("api/v2/song/all");
let url = syncers::common::retrieve_url(&self.api, false, &uuid::Uuid::nil()); let url = format!("{}{}", self.api.url, self.api.endpoint);
let access_token = token.bearer_token(); let access_token = token.bearer_token();
println!("url: {url:?}");
let client = reqwest::Client::builder().build().unwrap(); let client = reqwest::Client::builder().build().unwrap();
let response = client let response = client
.get(&url) .get(&url)
@@ -29,8 +41,11 @@ impl RetrieveRecords {
match response.status() { match response.status() {
reqwest::StatusCode::OK => { reqwest::StatusCode::OK => {
// on success, parse our JSON to an API Response // on success, parse our JSON to an API Response
match response.json::<Vec<icarus_models::song::Song>>().await { match response.json::<response::get_all_songs::Response>().await {
Ok(parsed) => Ok(parsed), Ok(parsed) => {
println!("Response message: {:?}", parsed.message);
Ok(parsed.data)
}
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(std::io::Error::other(err.to_string())),
} }
} }