Skip to content

Commit

Permalink
added substitutable
Browse files Browse the repository at this point in the history
  • Loading branch information
rithikha committed Mar 28, 2024
1 parent 3c16558 commit 04c773a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion zomes/rea_resource_specification/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
})
Expand Down
6 changes: 6 additions & 0 deletions zomes/rea_resource_specification/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct Response {
pub default_unit_of_effort: Option<UnitId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub default_unit_of_resource: Option<UnitId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub substitutable: Option<bool>,
}

/// I/O struct to describe what is returned outside the gateway.
Expand Down Expand Up @@ -78,6 +80,8 @@ pub struct CreateRequest {
pub default_unit_of_effort: MaybeUndefined<UnitId>,
#[serde(default)]
pub default_unit_of_resource: MaybeUndefined<UnitId>,
#[serde(default)]
pub substitutable: MaybeUndefined<bool>,
}

impl<'a> CreateRequest {
Expand All @@ -102,6 +106,8 @@ pub struct UpdateRequest {
pub default_unit_of_effort: MaybeUndefined<UnitId>,
#[serde(default)]
pub default_unit_of_resource: MaybeUndefined<UnitId>,
#[serde(default)]
pub substitutable: MaybeUndefined<bool>,
}

impl<'a> UpdateRequest {
Expand Down
37 changes: 32 additions & 5 deletions zomes/rea_resource_specification/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct EntryData {
pub default_unit_of_effort: Option<UnitId>,
pub default_unit_of_resource: Option<UnitId>,
pub _nonce: Bytes,
pub substitutable: Option<bool>,
}

generate_record_entry!(EntryData, ResourceSpecificationAddress, EntryStorage);
Expand Down Expand Up @@ -97,6 +98,7 @@ impl TryFrom<CreateRequest> 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(),
})
}
}
Expand All @@ -107,11 +109,36 @@ impl TryFrom<CreateRequest> for EntryData {
impl Updateable<UpdateRequest> for EntryData {
fn update_with(&self, e: UpdateRequest) -> RecordAPIResult<EntryData> {
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(),
})
}
Expand Down

0 comments on commit 04c773a

Please sign in to comment.