Add: Stamp stop feature

This commit is contained in:
Óscar M. Lage 2021-11-18 20:57:32 +01:00
parent 8a3a4520eb
commit ce2a0d2cbe
2 changed files with 34 additions and 0 deletions

View File

@ -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!!!"),

View File

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