From 04c773a0e6f2cf240e81362d41fd9a0afff5d3cc Mon Sep 17 00:00:00 2001 From: rithikha Date: Thu, 28 Mar 2024 19:38:34 -0400 Subject: [PATCH] added substitutable --- .../rea_resource_specification/lib/src/lib.rs | 2 +- .../rea_resource_specification/rpc/src/lib.rs | 6 +++ .../storage/src/lib.rs | 37 ++++++++++++++++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/zomes/rea_resource_specification/lib/src/lib.rs b/zomes/rea_resource_specification/lib/src/lib.rs index cfad0e8d8..d158fd22f 100644 --- a/zomes/rea_resource_specification/lib/src/lib.rs +++ b/zomes/rea_resource_specification/lib/src/lib.rs @@ -85,7 +85,7 @@ fn construct_response<'a>( note: e.note.to_owned(), default_unit_of_effort: e.default_unit_of_effort.to_owned(), default_unit_of_resource: e.default_unit_of_resource.to_owned(), - + substitutable: e.substitutable.to_owned(), // conforming_resources: conforming_resources.map(Cow::into_owned), } }) diff --git a/zomes/rea_resource_specification/rpc/src/lib.rs b/zomes/rea_resource_specification/rpc/src/lib.rs index 858851c5c..7b21a8180 100644 --- a/zomes/rea_resource_specification/rpc/src/lib.rs +++ b/zomes/rea_resource_specification/rpc/src/lib.rs @@ -50,6 +50,8 @@ pub struct Response { pub default_unit_of_effort: Option, #[serde(skip_serializing_if = "Option::is_none")] pub default_unit_of_resource: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub substitutable: Option, } /// I/O struct to describe what is returned outside the gateway. @@ -78,6 +80,8 @@ pub struct CreateRequest { pub default_unit_of_effort: MaybeUndefined, #[serde(default)] pub default_unit_of_resource: MaybeUndefined, + #[serde(default)] + pub substitutable: MaybeUndefined, } impl<'a> CreateRequest { @@ -102,6 +106,8 @@ pub struct UpdateRequest { pub default_unit_of_effort: MaybeUndefined, #[serde(default)] pub default_unit_of_resource: MaybeUndefined, + #[serde(default)] + pub substitutable: MaybeUndefined, } impl<'a> UpdateRequest { diff --git a/zomes/rea_resource_specification/storage/src/lib.rs b/zomes/rea_resource_specification/storage/src/lib.rs index ef7355b88..8559b93c3 100644 --- a/zomes/rea_resource_specification/storage/src/lib.rs +++ b/zomes/rea_resource_specification/storage/src/lib.rs @@ -45,6 +45,7 @@ pub struct EntryData { pub default_unit_of_effort: Option, pub default_unit_of_resource: Option, pub _nonce: Bytes, + pub substitutable: Option, } generate_record_entry!(EntryData, ResourceSpecificationAddress, EntryStorage); @@ -97,6 +98,7 @@ impl TryFrom for EntryData { default_unit_of_effort: e.default_unit_of_effort.into(), default_unit_of_resource: e.default_unit_of_resource.into(), _nonce: random_bytes(32)?, + substitutable: e.substitutable.into(), }) } } @@ -107,11 +109,36 @@ impl TryFrom for EntryData { impl Updateable for EntryData { fn update_with(&self, e: UpdateRequest) -> RecordAPIResult { Ok(EntryData { - name: if !e.name.is_some() { self.name.to_owned() } else { e.name.to_owned().unwrap() }, - image: if e.image.is_undefined() { self.image.to_owned() } else { e.image.to_owned().into() }, - note: if e.note.is_undefined() { self.note.to_owned() } else { e.note.to_owned().into() }, - default_unit_of_effort: if e.default_unit_of_effort.is_undefined() { self.default_unit_of_effort.to_owned() } else { e.default_unit_of_effort.to_owned().into() }, - default_unit_of_resource: if e.default_unit_of_resource.is_undefined() { self.default_unit_of_resource.to_owned() } else { e.default_unit_of_resource.to_owned().into() }, + name: if !e.name.is_some() { + self.name.to_owned() + } else { + e.name.to_owned().unwrap() + }, + image: if e.image.is_undefined() { + self.image.to_owned() + } else { + e.image.to_owned().into() + }, + note: if e.note.is_undefined() { + self.note.to_owned() + } else { + e.note.to_owned().into() + }, + default_unit_of_effort: if e.default_unit_of_effort.is_undefined() { + self.default_unit_of_effort.to_owned() + } else { + e.default_unit_of_effort.to_owned().into() + }, + default_unit_of_resource: if e.default_unit_of_resource.is_undefined() { + self.default_unit_of_resource.to_owned() + } else { + e.default_unit_of_resource.to_owned().into() + }, + substitutable: if e.substitutable.is_undefined() { + self.substitutable.to_owned() + } else { + e.substitutable.to_owned().into() + }, _nonce: self._nonce.to_owned(), }) }