Merge pull request #451 from matthiasbeyer/imag-notes/get

Imag notes/get
This commit is contained in:
Matthias Beyer 2016-05-28 23:59:41 +02:00
commit 1fd95c9ccd
2 changed files with 22 additions and 7 deletions

View file

@ -69,14 +69,19 @@ fn edit(rt: &Runtime) {
}
fn edit_entry(rt: &Runtime, name: String) -> bool {
let note = Note::retrieve(rt.store(), name);
if note.is_err() {
trace_error(&note.unwrap_err());
let mut note = match Note::get(rt.store(), name) {
Ok(Some(note)) => note,
Ok(None) => {
warn!("Cannot edit nonexistent Note");
return false
}
},
Err(e) => {
trace_error(&e);
warn!("Cannot edit nonexistent Note");
return false
},
};
let mut note = note.unwrap();
if let Err(e) = note.edit_content(rt) {
trace_error(&e);
warn!("Editing failed");

View file

@ -102,6 +102,16 @@ impl<'a> Note<'a> {
.map(|entry| Note { entry: entry })
}
pub fn get(store: &Store, name: String) -> Result<Option<Note>> {
use libimagerror::into::IntoError;
match store.get(ModuleEntryPath::new(name).into_storeid()) {
Ok(Some(entry)) => Ok(Some(Note { entry: entry })),
Ok(None) => Ok(None),
Err(e) => Err(NEK::StoreWriteError.into_error_with_cause(Box::new(e))),
}
}
pub fn all_notes(store: &Store) -> Result<NoteIterator> {
store.retrieve_for_module("notes")
.map(|iter| NoteIterator::new(store, iter))