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)]