Skip to content

Commit 28b2b03

Browse files
committed
Add update_here so updates are atomic at the zome level
1 parent dd95a7b commit 28b2b03

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

dna/zomes/where/src/here.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub struct Here {
1919
}
2020

2121

22-
/// Input to the create channel call
2322
#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
2423
#[serde(rename_all = "camelCase")]
2524
pub struct AddHereInput {
@@ -29,6 +28,14 @@ pub struct AddHereInput {
2928
pub meta: BTreeMap<String, String>,
3029
}
3130

31+
/// Input to update a Here
32+
#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
33+
#[serde(rename_all = "camelCase")]
34+
pub struct UpdateHereInput {
35+
old_here_hh: HeaderHashB64,
36+
new_here: AddHereInput,
37+
}
38+
3239
#[hdk_extern]
3340
fn add_here(input: AddHereInput) -> ExternResult<HeaderHashB64> {
3441
// Find session
@@ -46,6 +53,12 @@ fn add_here(input: AddHereInput) -> ExternResult<HeaderHashB64> {
4653
Ok(link_hh.into())
4754
}
4855

56+
#[hdk_extern]
57+
fn update_here(input: UpdateHereInput) -> ExternResult<HeaderHashB64> {
58+
delete_here(input.old_here_hh)?;
59+
add_here(input.new_here)
60+
}
61+
4962
#[hdk_extern]
5063
fn delete_here(link_hh: HeaderHashB64) -> ExternResult<()> {
5164
delete_link(link_hh.into())?;

ui/lib/src/where.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ export class WhereService {
133133
return this.callZome('add_here', input);
134134
}
135135

136+
async updateLocation(hereHh: HeaderHashB64, location: Location, spaceEh: EntryHashB64, sessionIndex: number): Promise<HeaderHashB64> {
137+
const entry = this.hereFromLocation(location);
138+
const input = {oldHereHh: hereHh, newHere: {spaceEh, sessionIndex, value: entry.value, meta: entry.meta}}
139+
return this.callZome('update_here', input);
140+
}
141+
136142
async deleteLocation(hereHh: HeaderHashB64): Promise<EntryHashB64> {
137143
return this.callZome('delete_here', hereHh);
138144
}

0 commit comments

Comments
 (0)