-
Notifications
You must be signed in to change notification settings - Fork 11
session4_data_models_p2 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: session4_data_models_p2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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<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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #[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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // ====================== 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(§ion_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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #[zome_fn("hc_public")] | ||||||||||||||||||||||||||||||||||||||
| fn delete_content(content_address: Address) -> ZomeApiResult<Address> { | ||||||||||||||||||||||||||||||||||||||
| content::handlers::delete(content_address) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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