diff --git a/README.org b/README.org index f5f5933..8b43b6f 100644 --- a/README.org +++ b/README.org @@ -67,6 +67,7 @@ struct System { #[derive(Serialize)] #[derive(Deserialize)] #[derive(Clone)] +#[derive(PartialEq)] struct Member { pk_id: String, sp_id: String, @@ -99,6 +100,7 @@ fn main() { //set_empty(config_path); } }, + //"get" => get(config_path), "memberlist" => memberlist(config_path), &_ => println!("Invalid command"), } @@ -201,12 +203,14 @@ fn set_member(config_path: String, tf_members: &[String]) -> Result<(), &'static } if to_front.len() != 0 { let fronters = get_fronters(&config["pk_key"].as_str().unwrap(), &config["sp_key"].as_str().unwrap(), &system); - pk_set_fronters(&config["pk_key"].as_str().unwrap(), &system, to_front, &fronters); } Ok(()) } +#+end_src +***** Memberlist +#+begin_src rust :tangle src/main.rs :comments link fn memberlist(config_path: String) { let sys = get_system(&config_path); @@ -230,7 +234,10 @@ fn pk_get_system(key: &str) -> Value { let res = http_get_request(url,key); return serde_json::from_str(&res.unwrap()).unwrap(); } +#+end_src +***** Get members +#+begin_src rust :tangle src/main.rs :comments link fn pk_get_members(key: &str, sysid: &str) -> Vec { let url = format!("{}/systems/{}/members", PK_URL, sysid); @@ -398,7 +405,10 @@ fn get_system(config_path: &str) -> System { return sys; } +#+end_src +***** Get fronters +#+begin_src rust :tangle src/main.rs :comments link fn get_fronters(pk_key: &str, sp_key: &str, sys: &System) -> HashMap> { let mut fronters: HashMap> = HashMap::new(); fronters.insert(String::from("pk"), pk_get_fronters(pk_key, sys)); @@ -409,6 +419,7 @@ fn get_fronters(pk_key: &str, sp_key: &str, sys: &System) -> HashMap Result> { @@ -423,8 +434,10 @@ async fn http_get_request(url: String, key: &str) -> Result>) -> Result<(), Box> { let client = reqwest::Client::new(); @@ -437,7 +450,10 @@ async fn http_post_request(url: String, key: &str, body: &HashMap<&str, Vec Result> { diff --git a/TODO.org b/TODO.org index 6ce4622..6a5ed97 100644 --- a/TODO.org +++ b/TODO.org @@ -8,20 +8,19 @@ :PROPERTIES: :COOKIE_DATA: recursive :END: -*** Milestone 1.0 [10/22][45%] -**** Main functions [4/11][36%] +*** Milestone 1.0 [12/24][50%] +**** Main functions [4/10][40%] ***** Finished Add `sync` command ***** HighPriority Add `set` command [2/3] -****** HighPriority [SET] Add empty +****** Backlog [SET] Add empty ****** Finished [SET] Add set ****** Finished Adapt to set multiple arguments -***** HighPriority Add `get` command -***** LowPriority Add `add` command [0/2] -****** LowPriority [ADD] Add empty -****** LowPriority [ADD] Add set -***** LowPriority Add `setgroup` command +***** InProgress Add `get` command +***** Backlog Add `add` command [0/2] +****** Backlog [ADD] Add empty +****** Backlog [ADD] Add set ***** Finished Add `memberlist` command -**** Utils [6/10][60%] +**** Utils [7/12][58%] ***** 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 @@ -29,31 +28,35 @@ ***** Finished http PATCH request ***** Finished http POST request ***** Finished Set members know the alias -***** HighPriority Compare if sent members are currently fronting and keep them otherwise add to fronting array +***** Finished Compare if sent members are currently fronting and keep them otherwise add to fronting array +***** InProgress Set simplyplural +***** InProgress Check if member is currently fronting and just add if not, remove the ones who do not ***** HighPriority Check for mismatch in fronting between pluralkit and simplyplural ***** LowPriority Get fronters handles the front file ***** HighPriority Rofi stuff -**** Doc [0/1][0%] -***** Functions [0/1] -****** Backlog Separate memberlist into its own code block in the readme +**** Exception handling [0/1][0%] +***** Backlog do it proper +**** Doc [1/1][100%] +***** Functions [1/1] +****** Finished Separate memberlist into its own code block in the readme ** Kanban -| Backlog | LowPriority | HighPriority | InProgress | Finished | -|--------------------------------+--------------------------------+--------------------------------+------------+--------------------------------| -| [[/home/alicia/git/pluralshit/TODO.org::separate memberlist into its own code block in the readme][separate memberlist into its o]] | [[/home/alicia/git/pluralshit/TODO.org::Add `add` command \[0/2\]][Add `add` command {0/2}]] | [[/home/alicia/git/pluralshit/TODO.org::Add `set` command \[2/3\]][Add `set` command {2/3}]] | | [[/home/alicia/git/pluralshit/TODO.org::Add `sync` command][Add `sync` command]] | -| | [[/home/alicia/git/pluralshit/TODO.org::\[ADD\] Add empty][{ADD} Add empty]] | [[/home/alicia/git/pluralshit/TODO.org::\[SET\] Add empty][{SET} Add empty]] | | [[/home/alicia/git/pluralshit/TODO.org::\[SET\] Add set][{SET} Add set]] | -| | [[/home/alicia/git/pluralshit/TODO.org::\[ADD\] Add set][{ADD} Add set]] | [[/home/alicia/git/pluralshit/TODO.org::Add `get` command][Add `get` command]] | | [[/home/alicia/git/pluralshit/TODO.org::Adapt to set multiple arguments][Adapt to set multiple argument]] | -| | [[/home/alicia/git/pluralshit/TODO.org::Add `setgroup` command][Add `setgroup` command]] | [[/home/alicia/git/pluralshit/TODO.org::Compare if sent members are currently fronting and keep them otherwise add to fronting array][Compare if sent members are cu]] | | [[/home/alicia/git/pluralshit/TODO.org::Add `memberlist` command][Add `memberlist` command]] | -| | [[/home/alicia/git/pluralshit/TODO.org::Get fronters handles the front file][Get fronters handles the front]] | [[/home/alicia/git/pluralshit/TODO.org::Check for mismatch in fronting between pluralkit and simplyplural][Check for mismatch in fronting]] | | [[/home/alicia/git/pluralshit/TODO.org::Add new function to get the config create empty in path if not exists][Add new function to get the co]] | -| | | [[/home/alicia/git/pluralshit/TODO.org::Rofi stuff][Rofi stuff]] | | [[/home/alicia/git/pluralshit/TODO.org::`Get system` if Value::Null sync and load json][`Get system` if Value::Null sy]] | -| | | | | [[/home/alicia/git/pluralshit/TODO.org::Get current front][Get current front]] | -| | | | | [[/home/alicia/git/pluralshit/TODO.org::http PATCH request][http PATCH request]] | -| | | | | [[/home/alicia/git/pluralshit/TODO.org::http POST request][http POST request]] | -| | | | | [[/home/alicia/git/pluralshit/TODO.org::Set members know the alias][Set members know the alias]] | -| | | | | | -| | | | | | -| | | | | | -| | | | | | -| | | | | | -| | | | | | +| Backlog | LowPriority | HighPriority | InProgress | Finished | +|-------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------| +| [[/home/alicia/git/pluralshit/TODO.org::\[SET\] Add empty][{SET} Add empty]] | [[/home/alicia/git/pluralshit/TODO.org::Get fronters handles the front file][Get fronters handles the front]] | [[/home/alicia/git/pluralshit/TODO.org::Add `set` command \[2/3\]][Add `set` command {2/3}]] | [[/home/alicia/git/pluralshit/TODO.org::Add `get` command][Add `get` command]] | [[/home/alicia/git/pluralshit/TODO.org::Add `sync` command][Add `sync` command]] | +| [[/home/alicia/git/pluralshit/TODO.org::Add `add` command \[0/2\]][Add `add` command {0/2}]] | | [[/home/alicia/git/pluralshit/TODO.org::Check for mismatch in fronting between pluralkit and simplyplural][Check for mismatch in fronting]] | [[/home/alicia/git/pluralshit/TODO.org::Set simplyplural][Set simplyplural]] | [[/home/alicia/git/pluralshit/TODO.org::\[SET\] Add set][{SET} Add set]] | +| [[/home/alicia/git/pluralshit/TODO.org::\[ADD\] Add empty][{ADD} Add empty]] | | [[/home/alicia/git/pluralshit/TODO.org::Rofi stuff][Rofi stuff]] | [[/home/alicia/git/pluralshit/TODO.org::Check if member is currently fronting and just add if not, remove the ones who do not][Check if member is currently f]] | [[/home/alicia/git/pluralshit/TODO.org::Adapt to set multiple arguments][Adapt to set multiple argument]] | +| [[/home/alicia/git/pluralshit/TODO.org::\[ADD\] Add set][{ADD} Add set]] | | | | [[/home/alicia/git/pluralshit/TODO.org::Add `memberlist` command][Add `memberlist` command]] | +| [[/home/alicia/git/pluralshit/TODO.org::do it proper][do it proper]] | | | | [[/home/alicia/git/pluralshit/TODO.org::Add new function to get the config create empty in path if not exists][Add new function to get the co]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::`Get system` if Value::Null sync and load json][`Get system` if Value::Null sy]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::Get current front][Get current front]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::http PATCH request][http PATCH request]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::http POST request][http POST request]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::Set members know the alias][Set members know the alias]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::Compare if sent members are currently fronting and keep them otherwise add to fronting array][Compare if sent members are cu]] | +| | | | | [[/home/alicia/git/pluralshit/TODO.org::Separate memberlist into its own code block in the readme][Separate memberlist into its o]] | +| | | | | | +| | | | | | +| | | | | | +| | | | | | #+TBLFM: @1='(kanban-headers $#)::@2$1..@>$>='(kanban-zero @# $# nil (list (buffer-file-name))) diff --git a/src/main.rs b/src/main.rs index b92585c..d13ce1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ struct System { #[derive(Serialize)] #[derive(Deserialize)] #[derive(Clone)] +#[derive(PartialEq)] struct Member { pk_id: String, sp_id: String, @@ -63,6 +64,7 @@ fn main() { //set_empty(config_path); } }, + //"get" => get(config_path), "memberlist" => memberlist(config_path), &_ => println!("Invalid command"), } @@ -161,12 +163,13 @@ fn set_member(config_path: String, tf_members: &[String]) -> Result<(), &'static } if to_front.len() != 0 { let fronters = get_fronters(&config["pk_key"].as_str().unwrap(), &config["sp_key"].as_str().unwrap(), &system); - pk_set_fronters(&config["pk_key"].as_str().unwrap(), &system, to_front, &fronters); } Ok(()) } +// Set member:1 ends here +// [[file:../README.org::*Memberlist][Memberlist:1]] fn memberlist(config_path: String) { let sys = get_system(&config_path); @@ -179,7 +182,7 @@ fn memberlist(config_path: String) { } } -// Set member:1 ends here +// Memberlist:1 ends here // [[file:../README.org::*Get system][Get system:1]] fn pk_get_system(key: &str) -> Value { @@ -188,7 +191,9 @@ fn pk_get_system(key: &str) -> Value { let res = http_get_request(url,key); return serde_json::from_str(&res.unwrap()).unwrap(); } +// Get system:1 ends here +// [[file:../README.org::*Get members][Get members:1]] fn pk_get_members(key: &str, sysid: &str) -> Vec { let url = format!("{}/systems/{}/members", PK_URL, sysid); @@ -197,43 +202,27 @@ fn pk_get_members(key: &str, sysid: &str) -> Vec { return datas; } -// Get system:1 ends here +// Get members:1 ends here // [[file:../README.org::*Get fronters][Get fronters:1]] -fn pk_get_fronters(key: &str, sys: &System) -> Vec { - let url = format!("{}/systems/{}/fronters", PK_URL, sys.pk_userid); +fn sp_get_fronters(key: &str, sys: &System) -> Vec { + let url = format!("{}/fronters", SP_URL); let res = http_get_request(url,key); - let data: Value = serde_json::from_str(&res.unwrap()).unwrap(); - let memberdata = &data["members"].as_array(); + let datas: Vec = serde_json::from_str(&res.unwrap()).unwrap(); let mut members: Vec = Vec::new(); - for member in memberdata { - for m in member.into_iter() { - for dbmem in &sys.members { - if m["name"].as_str().unwrap() == dbmem.name { - members.push(dbmem.clone()); - } + for data in datas { + let sp_id = &data["content"]["member"].as_str().unwrap(); + for member in &sys.members { + if &member.sp_id == sp_id { + members.push(member.clone()); } } - } + } return members; } - -fn pk_set_fronters(key: &str, sys: &System, to_front: Vec, _fronters: &HashMap>) { - let url = format!("{}/systems/{}/switches", PK_URL, sys.pk_userid); - - // if not fronting - - let mut frontcodes = Vec::new(); - for tf in to_front { - frontcodes.push(tf.pk_id); - } - let mut body: HashMap<&str, Vec> = HashMap::new(); - body.insert("members", frontcodes); - let _ = http_post_request(url, key, &body); -} // Get fronters:1 ends here // [[file:../README.org::*Get user ID][Get user ID:1]] @@ -278,20 +267,22 @@ fn get_sp_id(mem: &Member, ids: &HashMap) -> String { // Get ID from member:1 ends here // [[file:../README.org::*Get fronters][Get fronters:1]] -fn sp_get_fronters(key: &str, sys: &System) -> Vec { +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(); + 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 { - members.push(member.clone()); + push_name = String::from(&member.name); } } + members.push(push_name); } return members; @@ -360,7 +351,9 @@ fn get_system(config_path: &str) -> System { return sys; } +// Get system json:1 ends here +// [[file:../README.org::*Get fronters][Get fronters:1]] fn get_fronters(pk_key: &str, sp_key: &str, sys: &System) -> HashMap> { let mut fronters: HashMap> = HashMap::new(); fronters.insert(String::from("pk"), pk_get_fronters(pk_key, sys)); @@ -368,9 +361,9 @@ fn get_fronters(pk_key: &str, sp_key: &str, sys: &System) -> HashMap Result> { let client = reqwest::Client::new(); @@ -384,8 +377,9 @@ async fn http_get_request(url: String, key: &str) -> Result>) -> Result<(), Box> { let client = reqwest::Client::new(); @@ -398,7 +392,9 @@ async fn http_post_request(url: String, key: &str, body: &HashMap<&str, Vec Result> { @@ -415,4 +411,4 @@ async fn http_patch_request(url: String, key: &str) -> Result