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),