Add: list stamps
This commit is contained in:
parent
6c513d51a6
commit
b21b660b30
@ -19,6 +19,10 @@ pub fn build_cli() -> App<'static, 'static> {
|
||||
SubCommand::with_name("projects")
|
||||
.about("List of active projects"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("stamps")
|
||||
.about("List last stamps"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("tasks")
|
||||
.about("List of active tasks grouped by project")
|
||||
|
33
src/cmd.rs
33
src/cmd.rs
@ -35,6 +35,22 @@ struct TasksResponse {
|
||||
error: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Stamp {
|
||||
id: u32,
|
||||
user_id: u32,
|
||||
project_id: u32,
|
||||
start: Option<String>,
|
||||
end: Option<String>,
|
||||
description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct StampsResponse {
|
||||
data: Vec<Stamp>,
|
||||
error: String,
|
||||
}
|
||||
|
||||
pub fn api_call(config_file: &PathBuf, endpoint: String) -> Result<reqwest::blocking::Response, reqwest::Error> {
|
||||
// Config
|
||||
let mut default_config = config::Config::default();
|
||||
@ -98,3 +114,20 @@ pub fn get_tasks(config_file: &PathBuf, project: u32) {
|
||||
Err(e) => println!("Error happened: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_stamps(config_file: &PathBuf) {
|
||||
let response = api_call(&config_file, String::from("stamps"));
|
||||
// eprintln!("{:#?}", response);
|
||||
match response {
|
||||
Ok(parsed) => {
|
||||
let stamps = parsed.json::<StampsResponse>().unwrap();
|
||||
eprintln!("{:#?}", stamps);
|
||||
for stamp in stamps.data {
|
||||
println!("⏳ ({id}) {description}",
|
||||
id=stamp.id,
|
||||
description=stamp.description.unwrap());
|
||||
}
|
||||
}
|
||||
Err(e) => println!("Error happened: {}", e),
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,12 @@ fn main() {
|
||||
cmd::get_tasks(&config_file, project);
|
||||
}
|
||||
|
||||
// gst stamps
|
||||
("stamps", Some(_matches)) => {
|
||||
console::info("List of stamps");
|
||||
cmd::get_stamps(&config_file);
|
||||
}
|
||||
|
||||
_ => console::error("Whut!!!"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user