FEAT Can update a raw note.
This commit is contained in:
parent
1565fef001
commit
0f5d15ad14
|
@ -9,6 +9,9 @@ pub enum NoteStoreError {
|
|||
#[error("Invalid Note Structure")]
|
||||
InvalidNoteStructure(String),
|
||||
|
||||
#[error("Not found")]
|
||||
NotFound,
|
||||
|
||||
/// All other errors from the database.
|
||||
#[error(transparent)]
|
||||
DBError(#[from] sqlx::Error),
|
||||
|
|
|
@ -70,4 +70,30 @@ mod tests {
|
|||
assert_eq!(page.title, "Test page");
|
||||
assert!(page.note_id > 0);
|
||||
}
|
||||
|
||||
#[tokio::test(threaded_scheduler)]
|
||||
async fn reports_note_update_failure() {
|
||||
let storagepool = fresh_inmemory_database().await;
|
||||
let note_id = storagepool.insert_note("noteid", "notecontent", "note").await;
|
||||
assert!(note_id.is_ok(), "{:?}", note_id);
|
||||
|
||||
let update = storagepool.update_raw_note("badnote", "Bad Note Content").await;
|
||||
assert!(update.is_err());
|
||||
}
|
||||
|
||||
|
||||
#[tokio::test(threaded_scheduler)]
|
||||
async fn can_update_a_note() {
|
||||
let storagepool = fresh_inmemory_database().await;
|
||||
let note_id = storagepool.insert_note("noteid", "notecontent", "note").await;
|
||||
assert!(note_id.is_ok(), "{:?}", note_id);
|
||||
|
||||
let update = storagepool.update_raw_note("noteid", "Good Note Content").await;
|
||||
assert!(update.is_ok(), "{:?}", update);
|
||||
|
||||
let note = storagepool.fetch_raw_note("noteid").await;
|
||||
assert!(note.is_ok(), "{:?}", note);
|
||||
let note = note.unwrap();
|
||||
assert_eq!(note.content, "Good Note Content");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
UPDATE notes
|
||||
SET content = ?, updated_date = ?, lastview_date = ?
|
||||
WHERE uuid = ?;
|
|
@ -3,8 +3,7 @@ use crate::structs::{RawNote, RawPage};
|
|||
use chrono;
|
||||
use friendly_id;
|
||||
use sqlx;
|
||||
use sqlx::sqlite::SqlitePool;
|
||||
use sqlx::{sqlite::Sqlite, Executor};
|
||||
use sqlx::{sqlite::{Sqlite, SqlitePool}, Executor, Done};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// A handle to our Sqlite database.
|
||||
|
@ -60,6 +59,22 @@ impl NoteStore {
|
|||
insert_note(&*self.0, id, content, notetype).await
|
||||
}
|
||||
|
||||
pub async fn update_raw_note(&self, id: &str, content: &str) -> NoteResult<()> {
|
||||
let update_one_note_sql = include_str!("sql/update_one_note.sql");
|
||||
let now = chrono::Utc::now();
|
||||
let rows_updated = sqlx::query(update_one_note_sql)
|
||||
.bind(&content)
|
||||
.bind(&now)
|
||||
.bind(&now)
|
||||
.bind(&id)
|
||||
.execute(&*self.0).await?
|
||||
.rows_affected();
|
||||
match rows_updated {
|
||||
1 => Ok(()),
|
||||
_ => Err(NoteStoreError::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We're returning the raw page with the raw note id, note
|
||||
// the friendly ID. Is there a disconnect there? It's making me
|
||||
// furiously to think.
|
||||
|
|
Loading…
Reference in New Issue