From 03ee6e68384c9faeca4b7086b436cf9524c270cc Mon Sep 17 00:00:00 2001 From: schwente Date: Tue, 31 May 2016 13:34:50 +0200 Subject: [PATCH 1/4] Delete Function --- libimagtodo/src/delete.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libimagtodo/src/delete.rs b/libimagtodo/src/delete.rs index e69de29b..cdb16501 100644 --- a/libimagtodo/src/delete.rs +++ b/libimagtodo/src/delete.rs @@ -0,0 +1,31 @@ +// Needed for reading a Json File +// extern crate rustc_serialize; +// use rustc_serialize::json::Json; +// use std::fs::File; +// use std::io::Read; + +use std::ops::Deref; +use toml::Value; + +use libimagstore::store::Store; +use libimagstore::storeid::IntoStoreId; +use module_path::ModuleEntryPath; + +/// With the uuid we get the storeid and than we can delete the entry +fn deleteFunc(uuid: i32, store : &Store) { + // With this we can read from a .json File + // let mut file = File::open("text.json").unwrap(); + // let mut data = String::new(); + // file.rad_to_string(&mut data).unwrap(); + // + // let jeson = Json::from_str(&data).unwrap(); + // println!("{}", json.find_path(&["uuid"]).unwrap()); + + // With the uuid we get the storeid + let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); + // It deletes an entry + store.delete(store_id); + + println!("The {} was delete!", uuid); +} + From d5dd55820a7561074029e48d9c9c3e69e1664a88 Mon Sep 17 00:00:00 2001 From: schwente Date: Wed, 1 Jun 2016 12:54:33 +0200 Subject: [PATCH 2/4] Do the changes for the Delete function --- libimagtodo/src/delete.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libimagtodo/src/delete.rs b/libimagtodo/src/delete.rs index cdb16501..79dd8ca5 100644 --- a/libimagtodo/src/delete.rs +++ b/libimagtodo/src/delete.rs @@ -6,13 +6,14 @@ use std::ops::Deref; use toml::Value; +use uuid::Uuid; use libimagstore::store::Store; use libimagstore::storeid::IntoStoreId; use module_path::ModuleEntryPath; /// With the uuid we get the storeid and than we can delete the entry -fn deleteFunc(uuid: i32, store : &Store) { +fn deleteFunc(uuid: Uuid, store : &Store) { // With this we can read from a .json File // let mut file = File::open("text.json").unwrap(); // let mut data = String::new(); @@ -25,7 +26,5 @@ fn deleteFunc(uuid: i32, store : &Store) { let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); // It deletes an entry store.delete(store_id); - - println!("The {} was delete!", uuid); } From 11b0622804a4766d5d173f93862aad751781f579 Mon Sep 17 00:00:00 2001 From: schwente Date: Mon, 6 Jun 2016 14:16:53 +0200 Subject: [PATCH 3/4] Fixed the store.delete(...) Return Problem --- libimagtodo/src/delete.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libimagtodo/src/delete.rs b/libimagtodo/src/delete.rs index 79dd8ca5..13d418bf 100644 --- a/libimagtodo/src/delete.rs +++ b/libimagtodo/src/delete.rs @@ -4,16 +4,16 @@ // use std::fs::File; // use std::io::Read; -use std::ops::Deref; -use toml::Value; use uuid::Uuid; use libimagstore::store::Store; use libimagstore::storeid::IntoStoreId; use module_path::ModuleEntryPath; +use error::{TodoError, TodoErrorKind}; + /// With the uuid we get the storeid and than we can delete the entry -fn deleteFunc(uuid: Uuid, store : &Store) { +pub fn deleteFunc(uuid: Uuid, store : &Store) { // With this we can read from a .json File // let mut file = File::open("text.json").unwrap(); // let mut data = String::new(); @@ -25,6 +25,9 @@ fn deleteFunc(uuid: Uuid, store : &Store) { // With the uuid we get the storeid let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); // It deletes an entry - store.delete(store_id); + if let Err(e) = store.delete(store_id) { + return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))).unwrap(); + } + } From 21fa21859b93733638c226a91caabfd65c8204f0 Mon Sep 17 00:00:00 2001 From: schwente Date: Wed, 8 Jun 2016 12:54:11 +0200 Subject: [PATCH 4/4] Change the Error handling and remove unsed code --- libimagtodo/src/delete.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/libimagtodo/src/delete.rs b/libimagtodo/src/delete.rs index 13d418bf..317deaa0 100644 --- a/libimagtodo/src/delete.rs +++ b/libimagtodo/src/delete.rs @@ -1,9 +1,3 @@ -// Needed for reading a Json File -// extern crate rustc_serialize; -// use rustc_serialize::json::Json; -// use std::fs::File; -// use std::io::Read; - use uuid::Uuid; use libimagstore::store::Store; @@ -12,22 +6,14 @@ use module_path::ModuleEntryPath; use error::{TodoError, TodoErrorKind}; -/// With the uuid we get the storeid and than we can delete the entry -pub fn deleteFunc(uuid: Uuid, store : &Store) { - // With this we can read from a .json File - // let mut file = File::open("text.json").unwrap(); - // let mut data = String::new(); - // file.rad_to_string(&mut data).unwrap(); - // - // let jeson = Json::from_str(&data).unwrap(); - // println!("{}", json.find_path(&["uuid"]).unwrap()); - +/// With the uuid we get the storeid and then we can delete the entry +pub fn deleteFunc(uuid: Uuid, store : &Store) -> Result<(),TodoError> { // With the uuid we get the storeid let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); // It deletes an entry - if let Err(e) = store.delete(store_id) { - return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))).unwrap(); + match store.delete(store_id) { + Ok(val) => Ok(val), + Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), } - }