From 709f8cbf3c5146a0f53a6e9b6a4aeb3abd1aff35 Mon Sep 17 00:00:00 2001 From: Vika Date: Sat, 1 Jul 2023 20:40:38 +0300 Subject: micropub: use the new, better typed updates internally --- kittybox-rs/src/database/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'kittybox-rs/src/database/mod.rs') diff --git a/kittybox-rs/src/database/mod.rs b/kittybox-rs/src/database/mod.rs index 94a93ca..baae81d 100644 --- a/kittybox-rs/src/database/mod.rs +++ b/kittybox-rs/src/database/mod.rs @@ -5,6 +5,7 @@ use async_trait::async_trait; mod file; pub use crate::database::file::FileStorage; +use crate::micropub::MicropubUpdate; #[cfg(test)] mod memory; #[cfg(test)] @@ -295,10 +296,10 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync { /// Add post to feed. Some database implementations might have optimized ways to do this. async fn add_to_feed(&self, feed: &'_ str, post: &'_ str) -> Result<()> { - self.update_post(feed, serde_json::json!({"add": {"children": [post]}})).await + self.update_post(feed, serde_json::from_str(r#"{"add": {"children": [post]}}"#).unwrap()).await } async fn remove_from_feed(&self, feed: &'_ str, post: &'_ str) -> Result<()> { - self.update_post(feed, serde_json::json!({"delete": {"children": [post]}})).await + self.update_post(feed, serde_json::from_str(r#"{"delete": {"children": [post]}}"#).unwrap()).await } /// Modify a post using an update object as defined in the Micropub spec. @@ -308,7 +309,7 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync { /// each other's changes or simply corrupting something. Rejecting /// is allowed in case of concurrent updates if waiting for a lock /// cannot be done. - async fn update_post(&self, url: &'_ str, update: serde_json::Value) -> Result<()>; + async fn update_post(&self, url: &str, update: MicropubUpdate) -> Result<()>; /// Get a list of channels available for the user represented by the URL `user` to write to. async fn get_channels(&self, user: &'_ str) -> Result>; @@ -449,7 +450,7 @@ mod tests { backend .update_post( &key, - json!({ + serde_json::from_value(json!({ "url": &key, "add": { "category": ["testing"], @@ -457,7 +458,7 @@ mod tests { "replace": { "content": ["Different test content"] } - }), + })).unwrap(), ) .await .unwrap(); -- cgit 1.4.1