Merge pull request #451 from matthiasbeyer/imag-notes/get
Imag notes/get
This commit is contained in:
commit
1fd95c9ccd
2 changed files with 22 additions and 7 deletions
|
@ -69,14 +69,19 @@ fn edit(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit_entry(rt: &Runtime, name: String) -> bool {
|
fn edit_entry(rt: &Runtime, name: String) -> bool {
|
||||||
let note = Note::retrieve(rt.store(), name);
|
let mut note = match Note::get(rt.store(), name) {
|
||||||
if note.is_err() {
|
Ok(Some(note)) => note,
|
||||||
trace_error(¬e.unwrap_err());
|
Ok(None) => {
|
||||||
warn!("Cannot edit nonexistent Note");
|
warn!("Cannot edit nonexistent Note");
|
||||||
return false
|
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) {
|
if let Err(e) = note.edit_content(rt) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
warn!("Editing failed");
|
warn!("Editing failed");
|
||||||
|
|
|
@ -102,6 +102,16 @@ impl<'a> Note<'a> {
|
||||||
.map(|entry| Note { entry: entry })
|
.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> {
|
pub fn all_notes(store: &Store) -> Result<NoteIterator> {
|
||||||
store.retrieve_for_module("notes")
|
store.retrieve_for_module("notes")
|
||||||
.map(|iter| NoteIterator::new(store, iter))
|
.map(|iter| NoteIterator::new(store, iter))
|
||||||
|
|
Loading…
Reference in a new issue