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
Generated
+1 -1
View File
@@ -479,7 +479,7 @@ dependencies = [
[[package]]
name = "icarus-dm"
version = "0.6.6"
version = "0.6.7"
dependencies = [
"futures",
"http",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "icarus-dm"
version = "0.6.6"
version = "0.6.7"
rust-version = "1.88"
edition = "2024"
+1 -1
View File
@@ -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
+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 -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())),
}
}