From 51c1b32ce14a2ad7615b45609924b40a5eb92fe9 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 22 Jun 2023 22:36:51 +0300 Subject: Better Micropub update object typing --- kittybox-rs/src/micropub/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kittybox-rs/src/micropub/mod.rs b/kittybox-rs/src/micropub/mod.rs index da9c6a5..a55ea15 100644 --- a/kittybox-rs/src/micropub/mod.rs +++ b/kittybox-rs/src/micropub/mod.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use crate::database::{MicropubChannel, Storage, StorageError}; use crate::indieauth::backend::AuthBackend; use crate::indieauth::User; @@ -317,6 +319,12 @@ enum ActionType { Update, } +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum MicropubPropertyDeletion { + Properties(Vec), + Values(HashMap) +} #[derive(Serialize, Deserialize)] struct MicropubFormAction { action: ActionType, @@ -324,19 +332,20 @@ struct MicropubFormAction { } #[derive(Serialize, Deserialize, Debug)] -struct MicropubAction { +pub struct MicropubAction { action: ActionType, url: String, #[serde(skip_serializing_if = "Option::is_none")] - replace: Option, + replace: Option>, #[serde(skip_serializing_if = "Option::is_none")] - add: Option, + add: Option>, #[serde(skip_serializing_if = "Option::is_none")] - delete: Option, + delete: Option, } impl From for MicropubAction { fn from(a: MicropubFormAction) -> Self { + debug_assert!(matches!(a.action, ActionType::Delete)); Self { action: a.action, url: a.url, -- cgit 1.4.1