Updated api_parser and song model

This commit is contained in:
kdeng00
2024-04-08 13:27:45 -04:00
parent 66fb53185e
commit a071fc93ba
2 changed files with 60 additions and 17 deletions
+40 -11
View File
@@ -3,7 +3,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Song { pub struct Song {
pub id: Option<i32>, pub id: Option<i32>,
pub title: Option<String>, pub title: Option<String>,
@@ -41,22 +41,51 @@ impl Default for Song {
} }
impl Song { impl Song {
// TODO: Implement pub fn print_info(&self) {
pub fn print_info(&self) {} println!("Title: {:?}", self.title);
// TODO: Implement
pub fn song_path(&self) -> String {
return String::from("");
} }
// TODO: Implement pub fn song_path(&self) -> String {
pub fn generate_filename_from_track() -> i32 { // let directory = &self.directory.unwrap();
let directory = &<std::option::Option<std::string::String> as Clone>::clone(&self.directory).unwrap();
let mut buffer: String = directory.to_string();
let count = buffer.len();
if buffer.chars().nth(count-1) != Some('/') {
buffer += "/";
}
let filename = &<std::option::Option<std::string::String> as Clone>::clone(&self.filepath).unwrap();
buffer += filename;
return buffer;
}
// if 1 - wav, if 0 - mp3, anything else defaults to wav
pub fn generate_filename_from_track(&mut self, i_type: i32) -> i32 {
let mut filename: String = String::new();
if self.track.unwrap() < 10 {
filename += "0";
}
filename += &self.track.unwrap().to_string();
if i_type == 0 {
filename += ".mp3";
} else {
filename += ".wav";
}
// &mut self.filepath = Some(filename);
self.filepath = Some(filename);
return 0; return 0;
} }
// TODO: Implement // TODO: Implement
pub fn to_metadata_json() -> String { pub fn to_metadata_json(&self) -> Result<String, serde_json::Error> {
return String::from(""); return serde_json::to_string_pretty(&self);
} }
} }
+20 -6
View File
@@ -7,14 +7,28 @@ pub struct APIParser {
} }
impl APIParser { impl APIParser {
// pub fn init() -> APIParser {
// }
pub fn retrieve_api(&self) -> models::api::API { pub fn retrieve_api(&self) -> models::api::API {
return models::api::API::default(); return self.api;
} }
// TODO: Implement pub fn parse_api(&self) {
fn parse_api(&self) { let flags = self.ica_act.flags;
println!("Parsing api");
for (i, elem) in flags {
let arg = elem.flag;
let value = elem.value;
if arg == "-h" {
if value.chars().nth((value.len() - 1)) == '/' {
self.api.url = value;
} else {
self.api.url = value + "/";
}
break;
}
}
self.api.version = "v1";
} }
} }