Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 78 additions & 5 deletions dna/course/zomes/courses/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod courses {
None => return Ok(None),
}
}

// sections_address - do I need to replicate this in the sections CRUD? Seems weird to update the course this way.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi josh! Yep, we would need to have an update_section function as well.
update_course updates the entire course entry. This also makes it possible for update_course to technically either add or remove section in the sections field of course struct. However, if we do want to update the details of the section itself (which for now is only title), then we would need the update_section function :D

#[zome_fn("hc_public")]
fn update_course(
title: String,
Expand Down Expand Up @@ -102,11 +102,84 @@ mod courses {
course::handlers::get_my_enrolled_courses()
}

// Section
// ====================== Section definitions
// TODO: implement section entry definitions
// TODO: implement section CRUD methods
#[entry_def]
fn section_entry_definition() -> ValidatingEntryType {
course::entry::section_entry_def()
}

#[entry_def]
fn section_anchor_definition() -> ValidatingEntryType {
course::anchor::section_anchor_def()
}

// TODO: implement section CRUD methods --> fished out of modules "impl" right? or handlers?
#[zome_fn("hc_public")]
fn create_section(title: String, course_anchor_address: Address, timestamp: u64, anchor_address: Address,
) -> ZomeApiResult<Address> {
section::handlers::create(title, course_anchor_address, timestamp, anchor_address)
}

// Content
#[zome_fn("hc_public")]
fn get_latest_section_entry(
section_anchor_address: Address,
) -> ZomeApiResult<Option<section::entry::Section>> {
section::handlers::get_latest_section_entry(section_anchor_address)?;
}
// this is copied off the course methods code and changed... is the sections_address part relevant here or in the above code?
#[zome_fn("hc_public")]
fn update_section(
title: String,
course_anchor_address: Address,
timestamp: u64,
anchor_address: Address,
) -> ZomeApiResult<Address> {
section::handlers::update(title, course_anchor_address, timestamp, anchor_address)
}
Comment on lines +132 to +139
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi josh! For this one, we will need the section_anchor_address only and not the course_anchor_address! We don't need to change anything in the course since course entry stores the anchor address of the section. This means that no matter how many times we update the section entry, the section_anchor_address stored in the course entry will always point to the latest version of the section entry!
With this my suggestion would be,

Suggested change
fn update_section(
title: String,
course_anchor_address: Address,
timestamp: u64,
anchor_address: Address,
) -> ZomeApiResult<Address> {
section::handlers::update(title, course_anchor_address, timestamp, anchor_address)
}
fn update_section(
title: String,
section_anchor_address: Address,
timestamp: u64,
) -> ZomeApiResult<Address> {
section::handlers::update(title, section_anchor_address, timestamp)
}


#[zome_fn("hc_public")]
fn delete_section(section_anchor_address: Address) -> ZomeApiResult<Address> {
section::handlers::delete(section_anchor_address)
}
Comment on lines +142 to +144
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the explanation nastasia gave us last session, we would need to add timestamp in delete_section and update the timestamp of the course entry so that we will not be ending up having duplicate course entries (which causes the bug nastasia mentioned last session :D)

Suggested change
fn delete_section(section_anchor_address: Address) -> ZomeApiResult<Address> {
section::handlers::delete(section_anchor_address)
}
fn delete_section(section_anchor_address: Address, timestamp: u64) -> ZomeApiResult<Address> {
section::handlers::delete(section_anchor_address, timestamp)
}



// ====================== Content definitions
// TODO: implement content entry definition
// TODO: implement content CRUD methods
#[entry_def]
fn content_entry_definition() -> ValidatingEntryType {
course::entry::section_entry_def()
}

// TODO: implement content CRUD methods --> used section anchor addresses as content uses that anchor
#[zome_fn("hc_public")]
fn create_content(name: String,
section_anchor_address: Address,
url: String,
timestamp: u64,
description: String,
) -> ZomeApiResult<Address> {
content::handlers::create(name, section_anchor_address, url, timestamp, description) // defined in module
}

#[zome_fn("hc_public")]
fn get_contents(section_anchor_address: Address) -> ZomeApiResult<Vec<Address>> {
content::handlers::get_contents(&section_anchor_address)?;
}

#[zome_fn("hc_public")]
fn update_content(
name: String,
section_anchor_address: Address,
url: String,
timestamp: u64,
description: String,
) -> ZomeApiResult<Address> {
content::handlers::update(name, url, description, timestamp, section_anchor_address,)
}
Comment on lines +171 to +179
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for us to know which content we would like to update, we would need to provide the content_address of the content we are trying to update. And since content entry already has the section_anchor_address, we wouldnt be needing the section_anchor_address as the parameter of this function.

Suggested change
fn update_content(
name: String,
section_anchor_address: Address,
url: String,
timestamp: u64,
description: String,
) -> ZomeApiResult<Address> {
content::handlers::update(name, url, description, timestamp, section_anchor_address,)
}
fn update_content(
name: String,
content_address: Address,
url: String,
timestamp: u64,
description: String,
) -> ZomeApiResult<Address> {
content::handlers::update(name, url, description, timestamp, content_address)
}


#[zome_fn("hc_public")]
fn delete_content(content_address: Address) -> ZomeApiResult<Address> {
content::handlers::delete(content_address)
}
}