diff --git a/.gitignore b/.gitignore index 4b949f6..a879b92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /config.json +/system.json diff --git a/README.org b/README.org index b0bad8c..30424c0 100644 --- a/README.org +++ b/README.org @@ -56,6 +56,7 @@ const SP_URL: &str = "https://api.apparyllis.com/v1"; #[derive(Debug)] #[derive(Serialize)] #[derive(Deserialize)] +#[derive(Clone)] struct System { pk_userid: String, sp_userid: String, @@ -120,7 +121,7 @@ fn set_member(config_path: String, member: String) -> Result<(), &'static str> { let system: System = get_system(&config_path); let mut flag = false; - for mem in system.members { + for mem in &system.members { if mem.name.to_lowercase() == member.to_lowercase() { flag = true; } @@ -128,7 +129,7 @@ fn set_member(config_path: String, member: String) -> Result<(), &'static str> { if flag { println!("Member {member} found"); - + get_fronters(&config["pk_key"].as_str().unwrap(), &system.pk_userid, &config["sp_key"].as_str().unwrap(), &system); Ok(()) @@ -218,6 +219,24 @@ fn pk_get_members(key: &str, sysid: &str) -> Vec { return datas; } + +fn pk_get_fronters(key: &str, sysid: &str) -> Vec { + let url = format!("{}/systems/{}/fronters", PK_URL, sysid); + + let res = http_get_request(url,key); + let data: Value = serde_json::from_str(&res.unwrap()).unwrap(); + let memberdata = &data["members"].as_array(); + + let mut members: Vec = Vec::new(); + for member in memberdata { + for m in member.into_iter() { + let mname = m["name"].as_str().unwrap(); + members.push(String::from(mname)); + } + } + + return members; +} #+end_src **** Simplyplural @@ -256,6 +275,27 @@ fn get_sp_id(mem: &Member, ids: &HashMap) -> String { return member_id; } + +fn sp_get_fronters(key: &str, sys: &System) -> Vec { + let url = format!("{}/fronters", SP_URL); + + let res = http_get_request(url,key); + let datas: Vec = serde_json::from_str(&res.unwrap()).unwrap(); + + let mut members: Vec = Vec::new(); + for data in datas { + let sp_id = &data["content"]["member"].as_str().unwrap(); + let mut push_name = String::new(); + for member in &sys.members { + if &member.sp_id == sp_id { + push_name = String::from(&member.name); + } + } + members.push(push_name); + + } + return members; +} #+end_src **** Utilities @@ -317,6 +357,15 @@ fn get_system(config_path: &str) -> System { return sys; } + +fn get_fronters(pk_key: &str, pk_sysid: &str, sp_key: &str, sys: &System) -> HashMap> { + let mut fronters: HashMap> = HashMap::new(); + fronters.insert(String::from("pk"), pk_get_fronters(pk_key, pk_sysid)); + fronters.insert(String::from("sp"), sp_get_fronters(sp_key, sys)); + println!("{:?}", fronters); + + return fronters; +} #+end_src **** Http Request handler diff --git a/TODO.org b/TODO.org index 7833d2c..31422bf 100644 --- a/TODO.org +++ b/TODO.org @@ -23,6 +23,7 @@ ***** Json loading [2/2] ****** Finished Add new function to get the config create empty in path if not exists ****** Finished `Get system` if Value::Null sync and load json +***** InProgress Get current front ** Kanban | Backlog | LowPriority | HighPriority | InProgress | Finished | diff --git a/src/main.rs b/src/main.rs index 3ef52b5..cc544e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ const SP_URL: &str = "https://api.apparyllis.com/v1"; #[derive(Debug)] #[derive(Serialize)] #[derive(Deserialize)] +#[derive(Clone)] struct System { pk_userid: String, sp_userid: String, @@ -82,7 +83,7 @@ fn set_member(config_path: String, member: String) -> Result<(), &'static str> { let system: System = get_system(&config_path); let mut flag = false; - for mem in system.members { + for mem in &system.members { if mem.name.to_lowercase() == member.to_lowercase() { flag = true; } @@ -90,7 +91,7 @@ fn set_member(config_path: String, member: String) -> Result<(), &'static str> { if flag { println!("Member {member} found"); - + get_fronters(&config["pk_key"].as_str().unwrap(), &system.pk_userid, &config["sp_key"].as_str().unwrap(), &system); Ok(()) @@ -179,6 +180,24 @@ fn pk_get_members(key: &str, sysid: &str) -> Vec { return datas; } + +fn pk_get_fronters(key: &str, sysid: &str) -> Vec { + let url = format!("{}/systems/{}/fronters", PK_URL, sysid); + + let res = http_get_request(url,key); + let data: Value = serde_json::from_str(&res.unwrap()).unwrap(); + let memberdata = &data["members"].as_array(); + + let mut members: Vec = Vec::new(); + for member in memberdata { + for m in member.into_iter() { + let mname = m["name"].as_str().unwrap(); + members.push(String::from(mname)); + } + } + + return members; +} // Pluralkit:1 ends here // [[file:../README.org::*Simplyplural][Simplyplural:1]] @@ -216,6 +235,27 @@ fn get_sp_id(mem: &Member, ids: &HashMap) -> String { return member_id; } + +fn sp_get_fronters(key: &str, sys: &System) -> Vec { + let url = format!("{}/fronters", SP_URL); + + let res = http_get_request(url,key); + let datas: Vec = serde_json::from_str(&res.unwrap()).unwrap(); + + let mut members: Vec = Vec::new(); + for data in datas { + let sp_id = &data["content"]["member"].as_str().unwrap(); + let mut push_name = String::new(); + for member in &sys.members { + if &member.sp_id == sp_id { + push_name = String::from(&member.name); + } + } + members.push(push_name); + + } + return members; +} // Simplyplural:1 ends here // [[file:../README.org::*Utilities][Utilities:1]] @@ -276,6 +316,15 @@ fn get_system(config_path: &str) -> System { return sys; } + +fn get_fronters(pk_key: &str, pk_sysid: &str, sp_key: &str, sys: &System) -> HashMap> { + let mut fronters: HashMap> = HashMap::new(); + fronters.insert(String::from("pk"), pk_get_fronters(pk_key, pk_sysid)); + fronters.insert(String::from("sp"), sp_get_fronters(sp_key, sys)); + println!("{:?}", fronters); + + return fronters; +} // Utilities:1 ends here // [[file:../README.org::*Http Request handler][Http Request handler:1]]