From b21b660b30a89c25724771af2b61cc23e5c20ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Mon, 15 Nov 2021 19:04:30 +0100 Subject: [PATCH] Add: list stamps --- src/cli.rs | 4 ++++ src/cmd.rs | 33 +++++++++++++++++++++++++++++++++ src/main.rs | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index 07a0832..eb55de5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -19,6 +19,10 @@ pub fn build_cli() -> App<'static, 'static> { SubCommand::with_name("projects") .about("List of active projects"), ) + .subcommand( + SubCommand::with_name("stamps") + .about("List last stamps"), + ) .subcommand( SubCommand::with_name("tasks") .about("List of active tasks grouped by project") diff --git a/src/cmd.rs b/src/cmd.rs index 41c79ec..8e9449b 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -35,6 +35,22 @@ struct TasksResponse { error: String, } +#[derive(Serialize, Deserialize, Debug)] +struct Stamp { + id: u32, + user_id: u32, + project_id: u32, + start: Option, + end: Option, + description: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +struct StampsResponse { + data: Vec, + error: String, +} + pub fn api_call(config_file: &PathBuf, endpoint: String) -> Result { // Config let mut default_config = config::Config::default(); @@ -98,3 +114,20 @@ pub fn get_tasks(config_file: &PathBuf, project: u32) { Err(e) => println!("Error happened: {}", e), } } + +pub fn get_stamps(config_file: &PathBuf) { + let response = api_call(&config_file, String::from("stamps")); + // eprintln!("{:#?}", response); + match response { + Ok(parsed) => { + let stamps = parsed.json::().unwrap(); + eprintln!("{:#?}", stamps); + for stamp in stamps.data { + println!("⏳ ({id}) {description}", + id=stamp.id, + description=stamp.description.unwrap()); + } + } + Err(e) => println!("Error happened: {}", e), + } +} diff --git a/src/main.rs b/src/main.rs index 2426fa8..1394c85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,12 @@ fn main() { cmd::get_tasks(&config_file, project); } + // gst stamps + ("stamps", Some(_matches)) => { + console::info("List of stamps"); + cmd::get_stamps(&config_file); + } + _ => console::error("Whut!!!"), } }