From b5a90ce57c5aaa4d9a8eb70179071558512798e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 7 Feb 2022 21:59:30 +0100 Subject: [PATCH] support denoting entry entities in decomposed format (adding URLs) --- src/database/entry.rs | 24 +++++++++++++++++++++--- src/routes.rs | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/database/entry.rs b/src/database/entry.rs index 4adefaf..ab3fbea 100644 --- a/src/database/entry.rs +++ b/src/database/entry.rs @@ -8,11 +8,18 @@ use std::io::{Cursor, Write}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InEntry { - pub entity: Option
, + pub entity: Option, pub attribute: String, pub value: EntryValue, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum InAddress { + Address(String), + Components { t: String, c: String }, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Entry { pub entity: Address, @@ -123,8 +130,19 @@ impl TryFrom for Entry { fn try_from(in_entry: InEntry) -> Result { match in_entry.entity { - Some(entity) => Ok(Entry { - entity, + Some(address) => Ok(Entry { + entity: match address { + InAddress::Address(address) => address.parse()?, + InAddress::Components { t, c } => { + // I absolutely cannot handle serde magic right now + // TODO: make this automatically derive from `Address` definition + match t.as_str() { + "Attribute" => Address::Attribute(c), + "Url" => Address::Url(c), + _ => c.parse()?, + } + } + }, attribute: in_entry.attribute, value: in_entry.value, }), diff --git a/src/routes.rs b/src/routes.rs index f280fb0..d5fcf21 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -217,6 +217,7 @@ pub async fn get_object( debug!("{:?}", result); + // TODO: make this automatically derive from `Address` definition let (entity_type, entity_content) = match address { Address::Hash(_) => ("Hash", None), Address::Uuid(_) => ("Uuid", None),