Language Migration (#21)

* Blank slate

* Added gitignore

* Updated gitignore

* Added rust code

* Added modules

* Fixed build issues

* rustfmt

* Updated models

* Added parsers module

* Updated utilities module

* Updated main.rs

* Updated api_parser and song model

* Updated icarus_action model

* Updated structs in managers module

* Updated main.rs

* More changes

* Saving changes

* Added new struct and methods

* More changes. Not functional yet

* Changed name of the project

* Removed cmake workflow

* Adding rust workflow

* Adding code to the syncers module

* Cargo formatting

* Continuing work

* Adding code to the syncers module

* Added dependencies

* Adding more code to the syncers module

* Added more code to the syncers module

It's not 100 percent done yet, I'll work on other modules

* Added more code to the managers module

* Added code to request a token

* Cargo formatting

* Adding more code to multi target upload

* Adding more multi-target upload code and formatted code

* Added more multi-upload code

* cargo fmt

* Got uploading functional and cargo fmt-ing

* Uploading multi target works, but is buggy

Not all of the songs are being uploaded

* Added single target upload

* Single target upload is functional but need to revisit multi-target upload

Multi-target upload is broken now. Needs to be revisited

* Fixed multi target upload

* Can now retrieve songs

* Downloading functionality is working

* Delete functionality is operational

* Updated README

* More cleanup

* Added test
This commit was merged in pull request #21.
This commit is contained in:
Kun Deng
2024-06-15 12:22:17 -04:00
committed by GitHub
parent 5e9e7bc46a
commit ee4469b385
79 changed files with 2148 additions and 3376 deletions
+72
View File
@@ -0,0 +1,72 @@
use std::default::Default;
use reqwest;
use crate::models;
#[derive(Clone, Debug)]
pub struct Delete {
pub api: models::api::API,
}
impl Default for Delete {
fn default() -> Self {
Delete {
api: models::api::API::default(),
}
}
}
impl Delete {
pub async fn delete_song(
&mut self,
token: &models::token::Token,
song: &models::song::Song,
) -> Result<models::song::Song, std::io::Error> {
self.api.endpoint = "song/data/delete".to_owned();
let url = self.retrieve_url(&song);
let client = reqwest::Client::builder().build().unwrap();
let access_token = token.bearer_token();
let response = client
.delete(&url)
.header(reqwest::header::AUTHORIZATION, access_token)
.send()
.await
.unwrap();
let mut sng = models::song::Song::default();
match response.status() {
reqwest::StatusCode::OK => {
println!("Success!");
let s = response.json::<models::song::Song>().await;
match s {
//
Ok(parsed) => {
sng = parsed;
}
Err(er) => {
println!("Error {:?}", er);
}
};
}
other => {
panic!("Issue occurred: {:?}", other);
}
}
return Ok(sng);
}
fn retrieve_url(&self, song: &models::song::Song) -> String {
let api = &self.api;
let mut url: String = String::from(&api.url);
url += &String::from("api/");
url += &String::from(&api.version);
url += &String::from("/");
url += &String::from(&api.endpoint);
url += &String::from("/");
url += &song.id.unwrap().to_string();
return url;
}
}