From 5ce6fb8f60de713e582e9fc0c1b89d89c5ef19e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Mon, 22 Nov 2021 18:48:11 +0100 Subject: [PATCH] Add: Duration field in Stamp --- src/main.rs | 6 +++--- src/models/stamps.rs | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index f660f71..9158af5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,7 +112,7 @@ fn main() { match task { 0 => panic!("Need some task number to add the stamp"), _ => { - let stamp = Stamp::new(&config_file, dstart, dend, description, task); + let stamp = Stamp::new(&config_file, dstart, dend, description, task, ""); let added = stamp.api_post(&config_file, "stamp/add"); match added.status() { reqwest::StatusCode::OK => println!("OK"), @@ -124,7 +124,7 @@ fn main() { // gst stamp --stop else if stop == 1 { console::info("Stop last stamp"); - let stamp = Stamp::new(&config_file, "", "", "", 0); + let stamp = Stamp::new(&config_file, "", "", "", 0, ""); let stopped = stamp.api_post(&config_file, "stamp/stop"); match stopped.status() { reqwest::StatusCode::OK => println!("OK"), @@ -134,7 +134,7 @@ fn main() { // gst stamp --update --description "desc" --dstart "20120101" --dend "20120101" else if update == 1 { console::info("Update last stamp"); - let stamp = Stamp::new(&config_file, dstart, dend, description, task); + let stamp = Stamp::new(&config_file, dstart, dend, description, task, ""); let updated = stamp.api_post(&config_file, "stamp/update"); match updated.status() { reqwest::StatusCode::OK => println!("OK"), diff --git a/src/models/stamps.rs b/src/models/stamps.rs index 14f84eb..1f85228 100644 --- a/src/models/stamps.rs +++ b/src/models/stamps.rs @@ -12,6 +12,7 @@ pub struct Stamp { pub end: Option, pub description: Option, pub task_id: Option, + pub duration: Option, } impl Stamp { @@ -19,7 +20,8 @@ impl Stamp { dstart: &str, dend: &str, description: &str, - task: u32 + task: u32, + duration: &str, ) -> Stamp { // Config let mut default_config = config::Config::default(); @@ -32,6 +34,7 @@ impl Stamp { end: Some(dend.to_string()), description: Some(description.to_string()), task_id: Some(task), + duration: Some(duration.to_string()), } } @@ -80,19 +83,30 @@ impl Stamps { let stamps = parsed.json::().unwrap(); // eprintln!("{:#?}", stamps); for stamp in stamps.data { + let mut open: String = String::from(""); + match stamp.end { + None => open = "⏸️ ".to_string(), + _ => { + let op: String = format_args!("{duration}", + duration=stamp.duration.unwrap().to_string() + ).to_string(); + open = op; + } + } + let output: String = format_args!("⏳ ({id}) {open} - {description}", + open=open, + id=stamp.id, + description=stamp.description.unwrap() + ).to_string(); match project { 0 => { - println!("⏳ ({id}) {description}", - id=stamp.id, - description=stamp.description.unwrap()); + println!("{}", output); if last != 0 { break; } }, _ => { if project == stamp.project_id { - println!("⏳ ({id}) {description}", - id=stamp.id, - description=stamp.description.unwrap()); + println!("{}", output); if last != 0 { break; } } }