From ce2a0d2cbef93adcc6ff4d368b7323469194c83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Thu, 18 Nov 2021 20:57:32 +0100 Subject: [PATCH] Add: Stamp stop feature --- src/main.rs | 17 +++++++++++++++++ src/models/stamps.rs | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main.rs b/src/main.rs index a523d8f..e3376ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,6 +130,23 @@ fn main() { } } } + else if stop == 1 { + console::info("Stop last stamp"); + let stamp = Stamp { + id: 0, + user_id: 0, + project_id: 0, + start: Some("".to_string()), + end: Some("".to_string()), + description: Some("".to_string()), + task_id: Some(0), + }; + let stopped = stamp.stop(&config_file); + match stopped.status() { + reqwest::StatusCode::OK => println!("OK"), + other => println!("KO: {:?}, something happened", other), + } + } } _ => console::error("Whut!!!"), diff --git a/src/models/stamps.rs b/src/models/stamps.rs index 89cd11f..4c42006 100644 --- a/src/models/stamps.rs +++ b/src/models/stamps.rs @@ -32,6 +32,23 @@ impl Stamp { res.unwrap() } + #[tokio::main] + pub async fn stop(&self, config_file: &PathBuf) -> reqwest::Response { + // Config + let mut default_config = config::Config::default(); + let config = default_config.parse(&config_file); + + // Call api + let endpoint = format!("{}{}", &config.url, "stamp/stop"); + let client = reqwest::Client::new(); + let res = client.post(endpoint) + .header("Authorization", &config.key) + .json(&self) + .send() + .await; + + res.unwrap() + } } #[derive(Serialize, Deserialize, Debug)]