From b405e3de436986e6fbe96da13bf55d8c366ed56b Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Wed, 12 Aug 2020 16:21:47 +0200 Subject: [PATCH] Update lib.rs - Implement section entry definitions - Implement section CRUD methods - Implement content entry definitions - Implement content CRUD methods --- dna/course/zomes/courses/code/src/lib.rs | 83 ++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/dna/course/zomes/courses/code/src/lib.rs b/dna/course/zomes/courses/code/src/lib.rs index 541ce29..620b73a 100644 --- a/dna/course/zomes/courses/code/src/lib.rs +++ b/dna/course/zomes/courses/code/src/lib.rs @@ -102,11 +102,82 @@ mod courses { course::handlers::get_my_enrolled_courses() } - // Section - // TODO: implement section entry definitions - // TODO: implement section CRUD methods + // ====================== Section definitions + #[entry_def] + fn section_anchor_definition() -> ValidatingEntryType { + section::anchor::section_anchor_def() + } + + #[entry_def] + fn section_entry_definition() -> ValidatingEntryType { + section::entry::section_entry_def() + } + + #[zome_fn("hc_public")] + fn create_section(title: String, timestamp: u64) -> ZomeApiResult
{ + section::handlers::create(title, timestamp) + } + + #[zome_fn("hc_public")] + fn get_latest_section_entry( + section_anchor_address: Address, + ) -> ZomeApiResult> { + let latest_section_result = section::handlers::get_latest_section(§ion_anchor_address)?; + match latest_section_result { + Some((section_entry, _section_entry_address)) => { + return Ok(Some(section_entry)); + } + None => return Ok(None), + } + } + + #[zome_fn("hc_public")] + fn update_section( + title: String, + section_anchor_address: Address, + ) -> ZomeApiResult
{ + section::handlers::update(title, §ion_anchor_address) + } + + #[zome_fn("hc_public")] + fn delete_section(section_anchor_address: Address) -> ZomeApiResult
{ + section::handlers::delete(section_anchor_address) + } + + // ====================== Content definitions + #[entry_def] + fn content_entry_definition() -> ValidatingEntryType { + content::entry::content_entry_def() + } + + #[zome_fn("hc_public")] + fn create_content(name: String, timestamp: u64) -> ZomeApiResult
{ + content::handlers::create(name, timestamp) + } + + #[zome_fn("hc_public")] + fn get_latest_content_entry( + section_anchor_address: Address, + ) -> ZomeApiResult> { + let latest_content_result = content::handlers::get_latest_content(§ion_anchor_address)?; + match latest_content_result { + Some((content_entry, _section_entry_address)) => { + return Ok(Some(content_entry)); + } + None => return Ok(None), + } + } + + #[zome_fn("hc_public")] + fn update_content( + name: String, + section_anchor_address: Address, + ) -> ZomeApiResult
{ + content::handlers::update(name, §ion_anchor_address) + } - // Content - // TODO: implement content entry definition - // TODO: implement content CRUD methods + #[zome_fn("hc_public")] + fn delete_content(section_anchor_address: Address) -> ZomeApiResult
{ + content::handlers::delete(section_anchor_address) + } }