Add: Changes in Projects + Tasks
This commit is contained in:
parent
43f668a059
commit
9e3a84eb31
59
src/cmd.rs
59
src/cmd.rs
@ -52,21 +52,50 @@ pub fn api_call(config_file: &PathBuf, endpoint: String) -> Result<reqwest::bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_projects(config_file: &PathBuf) {
|
pub fn get_projects(config_file: &PathBuf) {
|
||||||
let projects_json = api_call(&config_file, String::from("stamps"));
|
let response = api_call(&config_file, String::from("projects"));
|
||||||
println!("{:?}", projects_json);
|
// eprintln!("{:#?}", response);
|
||||||
|
match response {
|
||||||
|
Ok(parsed) => {
|
||||||
|
let projects = parsed.json::<ProjectsResponse>().unwrap();
|
||||||
|
for project in projects.data {
|
||||||
|
println!("➡️ ({id}) {name} (uid: {uid})",
|
||||||
|
id=project.id,
|
||||||
|
name=project.name,
|
||||||
|
uid=project.user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => println!("Error happened: {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_tasks(config_file: &PathBuf, project: i32) {
|
pub fn get_tasks(config_file: &PathBuf, project: u32) {
|
||||||
// Config
|
let response = api_call(&config_file, String::from("tasks"));
|
||||||
let mut default_config = config::Config::default();
|
// eprintln!("{:#?}", response);
|
||||||
let config = default_config.parse(&config_file);
|
match response {
|
||||||
|
Ok(parsed) => {
|
||||||
// Call api
|
// println!("{:?}", parsed);
|
||||||
println!("Call API, Config: {:?}", config);
|
let tasks = parsed.json::<TasksResponse>().unwrap();
|
||||||
|
for task in tasks.data {
|
||||||
// Return json result
|
match project {
|
||||||
let tasks = String::from("tasks");
|
// 0 means no project, print them all
|
||||||
println!("{}", tasks);
|
0 => {
|
||||||
|
println!("✳️ (pr: {projectid}) ({id}) {name}",
|
||||||
println!("{}", project);
|
projectid=task.project_id,
|
||||||
|
id=task.id,
|
||||||
|
name=task.name);
|
||||||
|
},
|
||||||
|
// Otherwise but 0, print only task with that project.id
|
||||||
|
_ => {
|
||||||
|
if project == task.project_id {
|
||||||
|
println!("✳️ (pr: {projectid}) ({id}) {name}",
|
||||||
|
projectid=task.project_id,
|
||||||
|
id=task.id,
|
||||||
|
name=task.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => println!("Error happened: {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// gst tasks [--project]
|
// gst tasks [--project]
|
||||||
("tasks", Some(matches)) => {
|
("tasks", Some(_matches)) => {
|
||||||
console::info("List of tasks");
|
console::info("List of tasks");
|
||||||
let project = matches.value_of("project")
|
let project = _matches.value_of("project")
|
||||||
.unwrap_or("0").trim().parse()
|
.unwrap_or("0").trim().parse()
|
||||||
.expect("Type a number!");
|
.expect("Type a number!");
|
||||||
cmd::get_tasks(&config_file, project);
|
cmd::get_tasks(&config_file, project);
|
||||||
|
Loading…
Reference in New Issue
Block a user