Refactor: stamp add() stop() and update() are now api_post() + added
update branch too
This commit is contained in:
parent
40d74ef0bf
commit
56e02021c7
36
src/main.rs
36
src/main.rs
@ -112,16 +112,8 @@ fn main() {
|
|||||||
match task {
|
match task {
|
||||||
0 => panic!("Need some task number to add the stamp"),
|
0 => panic!("Need some task number to add the stamp"),
|
||||||
_ => {
|
_ => {
|
||||||
let stamp = Stamp {
|
let stamp = Stamp::new(&config_file, dstart, dend, description, task);
|
||||||
id: 0,
|
let added = stamp.api_post(&config_file, "stamp/add");
|
||||||
user_id: 0,
|
|
||||||
project_id: 0,
|
|
||||||
start: Some(dstart.to_string()),
|
|
||||||
end: Some(dend.to_string()),
|
|
||||||
description: Some(description.to_string()),
|
|
||||||
task_id: Some(task),
|
|
||||||
};
|
|
||||||
let added = stamp.add(&config_file);
|
|
||||||
match added.status() {
|
match added.status() {
|
||||||
reqwest::StatusCode::OK => println!("OK"),
|
reqwest::StatusCode::OK => println!("OK"),
|
||||||
err => println!("KO: {:?}, something happened", err),
|
err => println!("KO: {:?}, something happened", err),
|
||||||
@ -132,16 +124,8 @@ fn main() {
|
|||||||
// gst stamp --stop
|
// gst stamp --stop
|
||||||
else if stop == 1 {
|
else if stop == 1 {
|
||||||
console::info("Stop last stamp");
|
console::info("Stop last stamp");
|
||||||
let stamp = Stamp {
|
let stamp = Stamp::new(&config_file, "", "", "", 0);
|
||||||
id: 0,
|
let stopped = stamp.api_post(&config_file, "stamp/stop");
|
||||||
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() {
|
match stopped.status() {
|
||||||
reqwest::StatusCode::OK => println!("OK"),
|
reqwest::StatusCode::OK => println!("OK"),
|
||||||
err => println!("KO: {:?}, something happened", err),
|
err => println!("KO: {:?}, something happened", err),
|
||||||
@ -150,12 +134,12 @@ fn main() {
|
|||||||
// gst stamp --update --description "desc" --dstart "20120101" --dend "20120101"
|
// gst stamp --update --description "desc" --dstart "20120101" --dend "20120101"
|
||||||
else if update == 1 {
|
else if update == 1 {
|
||||||
console::info("Update last stamp");
|
console::info("Update last stamp");
|
||||||
// let stamp = {
|
let stamp = Stamp::new(&config_file, dstart, dend, description, task);
|
||||||
// // description
|
let updated = stamp.api_post(&config_file, "stamp/update");
|
||||||
// // dstart
|
match updated.status() {
|
||||||
// // dend
|
reqwest::StatusCode::OK => println!("OK"),
|
||||||
// };
|
err => println!("KO: {:?}, something happened", err),
|
||||||
// stamp.update();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,13 +36,13 @@ impl Stamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn stop(&self, config_file: &PathBuf) -> reqwest::Response {
|
pub async fn api_post(&self, config_file: &PathBuf, endpoint: &str) -> reqwest::Response {
|
||||||
// Config
|
// Config
|
||||||
let mut default_config = config::Config::default();
|
let mut default_config = config::Config::default();
|
||||||
let config = default_config.parse(&config_file);
|
let config = default_config.parse(&config_file);
|
||||||
|
|
||||||
// Call api
|
// Call api
|
||||||
let endpoint = format!("{}{}", &config.url, "stamp/stop");
|
let endpoint = format!("{}{}", &config.url, String::from(endpoint));
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let res = client.post(endpoint)
|
let res = client.post(endpoint)
|
||||||
.header("Authorization", &config.key)
|
.header("Authorization", &config.key)
|
||||||
|
Loading…
Reference in New Issue
Block a user