From 9e3a84eb3159d21c41efec44216bd9cbcc674f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Mon, 15 Nov 2021 18:39:44 +0100 Subject: [PATCH] Add: Changes in Projects + Tasks --- src/cmd.rs | 59 +++++++++++++++++++++++++++++++++++++++-------------- src/main.rs | 4 ++-- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index e6a6ff2..09fad6c 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -52,21 +52,50 @@ pub fn api_call(config_file: &PathBuf, endpoint: String) -> Result { + let projects = parsed.json::().unwrap(); + for project in projects.data { + println!("➡️ ({id}) {name} (uid: {uid})", + id=project.id, + name=project.name, + uid=project.user_id); + } + } + Err(e) => println!("Error happened: {}", e), + } } -pub fn get_tasks(config_file: &PathBuf, project: i32) { - // Config - let mut default_config = config::Config::default(); - let config = default_config.parse(&config_file); - - // Call api - println!("Call API, Config: {:?}", config); - - // Return json result - let tasks = String::from("tasks"); - println!("{}", tasks); - - println!("{}", project); +pub fn get_tasks(config_file: &PathBuf, project: u32) { + let response = api_call(&config_file, String::from("tasks")); + // eprintln!("{:#?}", response); + match response { + Ok(parsed) => { + // println!("{:?}", parsed); + let tasks = parsed.json::().unwrap(); + for task in tasks.data { + match project { + // 0 means no project, print them all + 0 => { + println!("✳️ (pr: {projectid}) ({id}) {name}", + projectid=task.project_id, + id=task.id, + name=task.name); + }, + // Otherwise but 0, print only task with that project.id + _ => { + if project == task.project_id { + println!("✳️ (pr: {projectid}) ({id}) {name}", + projectid=task.project_id, + id=task.id, + name=task.name); + } + } + } + } + } + Err(e) => println!("Error happened: {}", e), + } } diff --git a/src/main.rs b/src/main.rs index 28052dd..2426fa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,9 +27,9 @@ fn main() { } // gst tasks [--project] - ("tasks", Some(matches)) => { + ("tasks", Some(_matches)) => { console::info("List of tasks"); - let project = matches.value_of("project") + let project = _matches.value_of("project") .unwrap_or("0").trim().parse() .expect("Type a number!"); cmd::get_tasks(&config_file, project);