Add: list stamps

This commit is contained in:
Óscar M. Lage 2021-11-15 19:04:30 +01:00
parent 6c513d51a6
commit b21b660b30
3 changed files with 43 additions and 0 deletions

View File

@ -19,6 +19,10 @@ pub fn build_cli() -> App<'static, 'static> {
SubCommand::with_name("projects") SubCommand::with_name("projects")
.about("List of active projects"), .about("List of active projects"),
) )
.subcommand(
SubCommand::with_name("stamps")
.about("List last stamps"),
)
.subcommand( .subcommand(
SubCommand::with_name("tasks") SubCommand::with_name("tasks")
.about("List of active tasks grouped by project") .about("List of active tasks grouped by project")

View File

@ -35,6 +35,22 @@ struct TasksResponse {
error: String, 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> { pub fn api_call(config_file: &PathBuf, endpoint: String) -> Result<reqwest::blocking::Response, reqwest::Error> {
// Config // Config
let mut default_config = config::Config::default(); 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), 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),
}
}

View File

@ -35,6 +35,12 @@ fn main() {
cmd::get_tasks(&config_file, project); cmd::get_tasks(&config_file, project);
} }
// gst stamps
("stamps", Some(_matches)) => {
console::info("List of stamps");
cmd::get_stamps(&config_file);
}
_ => console::error("Whut!!!"), _ => console::error("Whut!!!"),
} }
} }