diff --git a/src/api/mod.rs b/src/api/mod.rs index 70b1be9..a8c43e1 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -280,23 +280,40 @@ impl VikunjaAPI { self.delete_request(&format!("/tasks/{id}")); } - pub fn new_task(&self, title: &str, project: &ProjectID) -> Task { + pub fn new_task( + &self, + title: &str, + project: &ProjectID, + description: Option, + due_date: Option, + fav: bool, + label: Option, + priority: Option, + ) -> Result { let id = project.0; + let labels = if let Some(label) = label { + let label = self + .get_all_labels() + .into_iter() + .find(|x| x.title.trim() == label) + .map_or_else(|| Err(format!("Label '{label}' not found")), Ok)?; + vec![label] + } else { + vec![] + }; + let data = serde_json::json!({ - "title": title + "title": title, + "description": description, + "due_date": due_date, + "is_favorite": fav, + "priority": priority, + "labels": labels }); - // todo : - // description - // due_date - // end_date - // is_favorite - // labels - // priority - let resp = self.put_request(&format!("/projects/{id}/tasks"), &data); - serde_json::from_str(&resp).unwrap() + Ok(serde_json::from_str(&resp).unwrap()) } pub fn done_task(&self, task_id: isize, done: bool) -> Option { diff --git a/src/args.rs b/src/args.rs index c0694e0..5e37971 100644 --- a/src/args.rs +++ b/src/args.rs @@ -49,7 +49,12 @@ pub fn get_args() -> clap::ArgMatches { arg!(-p --project "Project to add task to") .required(false) .default_value("Inbox"), - ), + ) + .arg(arg!(-d --description "Task Description").required(false)) + .arg(arg!(--due "Task Due").required(false)) + .arg(arg!(-l --label