From 283ad2158bf353d5020f45d9fe700d9dff6d1e6a Mon Sep 17 00:00:00 2001 From: Josh Fairhead <34649155+Joshfairhead@users.noreply.github.com> Date: Tue, 18 Aug 2020 14:29:44 +0100 Subject: [PATCH] session4_data_models_p2 Wow I'm struggling with git lol, cant seem to pull the various branches with homework to local, just master... so making this PR is a total hack via github branch! I've had the advantage of being able to see the answers this time round which made implementing the CRUDs easier... but I did not copy them directly! My strategy was to give it a go by directly copying the bits that were already implemented and changing the names (which is how I did it last time)... that turned out to be wrong when I checked it against the solution. What I found was that the pieces to feed into the function (are these methods?) was that the fields I needed were either in the module of entry/anchor or in the handlers... I'm not sure where I should be lifting the fields from to be honest or how they connect yet despite watching the videos a bunch of times... so behind on validation at this point... --- dna/course/zomes/courses/code/src/lib.rs | 83 ++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/dna/course/zomes/courses/code/src/lib.rs b/dna/course/zomes/courses/code/src/lib.rs index 541ce29..430afc8 100644 --- a/dna/course/zomes/courses/code/src/lib.rs +++ b/dna/course/zomes/courses/code/src/lib.rs @@ -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. #[zome_fn("hc_public")] fn update_course( title: String, @@ -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
{ + 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> { + 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
{ + section::handlers::update(title, course_anchor_address, timestamp, anchor_address) + } + + #[zome_fn("hc_public")] + fn delete_section(section_anchor_address: Address) -> ZomeApiResult
{ + section::handlers::delete(section_anchor_address) + } + + + // ====================== 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
{ + 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> { + content::handlers::get_contents(§ion_anchor_address)?; + } + + #[zome_fn("hc_public")] + fn update_content( + name: String, + section_anchor_address: Address, + url: String, + timestamp: u64, + description: String, + ) -> ZomeApiResult
{ + content::handlers::update(name, url, description, timestamp, section_anchor_address,) + } + + #[zome_fn("hc_public")] + fn delete_content(content_address: Address) -> ZomeApiResult
{ + content::handlers::delete(content_address) + } }