Skip to content

Commit 04c773a

Browse files
committed
added substitutable
1 parent 3c16558 commit 04c773a

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

zomes/rea_resource_specification/lib/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn construct_response<'a>(
8585
note: e.note.to_owned(),
8686
default_unit_of_effort: e.default_unit_of_effort.to_owned(),
8787
default_unit_of_resource: e.default_unit_of_resource.to_owned(),
88-
88+
substitutable: e.substitutable.to_owned(),
8989
// conforming_resources: conforming_resources.map(Cow::into_owned),
9090
}
9191
})

zomes/rea_resource_specification/rpc/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ pub struct Response {
5050
pub default_unit_of_effort: Option<UnitId>,
5151
#[serde(skip_serializing_if = "Option::is_none")]
5252
pub default_unit_of_resource: Option<UnitId>,
53+
#[serde(skip_serializing_if = "Option::is_none")]
54+
pub substitutable: Option<bool>,
5355
}
5456

5557
/// I/O struct to describe what is returned outside the gateway.
@@ -78,6 +80,8 @@ pub struct CreateRequest {
7880
pub default_unit_of_effort: MaybeUndefined<UnitId>,
7981
#[serde(default)]
8082
pub default_unit_of_resource: MaybeUndefined<UnitId>,
83+
#[serde(default)]
84+
pub substitutable: MaybeUndefined<bool>,
8185
}
8286

8387
impl<'a> CreateRequest {
@@ -102,6 +106,8 @@ pub struct UpdateRequest {
102106
pub default_unit_of_effort: MaybeUndefined<UnitId>,
103107
#[serde(default)]
104108
pub default_unit_of_resource: MaybeUndefined<UnitId>,
109+
#[serde(default)]
110+
pub substitutable: MaybeUndefined<bool>,
105111
}
106112

107113
impl<'a> UpdateRequest {

zomes/rea_resource_specification/storage/src/lib.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct EntryData {
4545
pub default_unit_of_effort: Option<UnitId>,
4646
pub default_unit_of_resource: Option<UnitId>,
4747
pub _nonce: Bytes,
48+
pub substitutable: Option<bool>,
4849
}
4950

5051
generate_record_entry!(EntryData, ResourceSpecificationAddress, EntryStorage);
@@ -97,6 +98,7 @@ impl TryFrom<CreateRequest> for EntryData {
9798
default_unit_of_effort: e.default_unit_of_effort.into(),
9899
default_unit_of_resource: e.default_unit_of_resource.into(),
99100
_nonce: random_bytes(32)?,
101+
substitutable: e.substitutable.into(),
100102
})
101103
}
102104
}
@@ -107,11 +109,36 @@ impl TryFrom<CreateRequest> for EntryData {
107109
impl Updateable<UpdateRequest> for EntryData {
108110
fn update_with(&self, e: UpdateRequest) -> RecordAPIResult<EntryData> {
109111
Ok(EntryData {
110-
name: if !e.name.is_some() { self.name.to_owned() } else { e.name.to_owned().unwrap() },
111-
image: if e.image.is_undefined() { self.image.to_owned() } else { e.image.to_owned().into() },
112-
note: if e.note.is_undefined() { self.note.to_owned() } else { e.note.to_owned().into() },
113-
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() },
114-
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() },
112+
name: if !e.name.is_some() {
113+
self.name.to_owned()
114+
} else {
115+
e.name.to_owned().unwrap()
116+
},
117+
image: if e.image.is_undefined() {
118+
self.image.to_owned()
119+
} else {
120+
e.image.to_owned().into()
121+
},
122+
note: if e.note.is_undefined() {
123+
self.note.to_owned()
124+
} else {
125+
e.note.to_owned().into()
126+
},
127+
default_unit_of_effort: if e.default_unit_of_effort.is_undefined() {
128+
self.default_unit_of_effort.to_owned()
129+
} else {
130+
e.default_unit_of_effort.to_owned().into()
131+
},
132+
default_unit_of_resource: if e.default_unit_of_resource.is_undefined() {
133+
self.default_unit_of_resource.to_owned()
134+
} else {
135+
e.default_unit_of_resource.to_owned().into()
136+
},
137+
substitutable: if e.substitutable.is_undefined() {
138+
self.substitutable.to_owned()
139+
} else {
140+
e.substitutable.to_owned().into()
141+
},
115142
_nonce: self._nonce.to_owned(),
116143
})
117144
}

0 commit comments

Comments
 (0)