diff --git a/dna/course/zomes/courses/code/src/content/entry.rs b/dna/course/zomes/courses/code/src/content/entry.rs new file mode 100644 index 0000000..e5624d7 --- /dev/null +++ b/dna/course/zomes/courses/code/src/content/entry.rs @@ -0,0 +1,58 @@ +use hdk::{ + entry_definition::ValidatingEntryType, + holochain_core_types::{dna::entry_types::Sharing, validation::EntryValidationData}, + holochain_json_api::{error::JsonError, json::JsonString}, + holochain_persistence_api::cas::content::Address, +}; +use holochain_entry_utils::HolochainEntry; + +#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone)] +pub struct Content { + pub title: String, + pub timestamp: u64, + pub anchor_address: Address, +} + +impl Content { + pub fn new( + title: String, + timestamp: u64, + anchor_address: Address, + ) -> Self { + title: title, + timestamp: timestamp, + anchor_address: anchor_address, + } +} + +impl HolochainEntry for Content { + fn entry_type() -> String { + String::from("section") + } +} + +// Holochain entry definition for Content +pub fn content_entry_def() -> ValidatingEntryType { + entry!( + name: Content::entry_type(), + description: "this is the definition of content", + sharing: Sharing::Public, + validation_package: || { + hdk::ValidationPackageDefinition::Entry + }, + validation: | validation_data: hdk::EntryValidationData| { + match validation_data { + EntryValidationData::Create { .. } => { + Ok(()) + }, + EntryValidationData::Modify { .. } => { + Ok(()) + }, + EntryValidationData::Delete { .. } => { + Ok(()) + } + } + }, + links: [] + ) +} diff --git a/dna/course/zomes/courses/code/src/content/mod.rs b/dna/course/zomes/courses/code/src/content/mod.rs new file mode 100644 index 0000000..eb5becf --- /dev/null +++ b/dna/course/zomes/courses/code/src/content/mod.rs @@ -0,0 +1 @@ +pub mod entry; diff --git a/dna/course/zomes/courses/code/src/lib.rs b/dna/course/zomes/courses/code/src/lib.rs index 982786f..6812669 100644 --- a/dna/course/zomes/courses/code/src/lib.rs +++ b/dna/course/zomes/courses/code/src/lib.rs @@ -22,6 +22,8 @@ use hdk_proc_macros::zome; mod anchor_trait; mod course; +mod section; +mod content; #[zome] mod courses { @@ -54,9 +56,20 @@ mod courses { course::entry::course_entry_def() } - // Section - // TODO: implement section entry definitions + // ====================== Section definitions + #[entry_def] + fn section_anchor_definition() -> ValidatingEntryType { + section::anchor::section_anchor_def() + } - // Content - // TODO: implement content entry definition + #[entry_def] + fn section_entry_definition() -> ValidatingEntryType { + section::entry::section_entry_def() + } + + // ====================== Content definitions + #[entry_def] + fn content_entry_definition() -> ValidatingEntryType { + content::entry::content_entry_def() + } } diff --git a/dna/course/zomes/courses/code/src/section/anchor.rs b/dna/course/zomes/courses/code/src/section/anchor.rs new file mode 100644 index 0000000..337382a --- /dev/null +++ b/dna/course/zomes/courses/code/src/section/anchor.rs @@ -0,0 +1,62 @@ +#[derive(Serialize, Deserialize, Debug,self::DefaultJson, Clone)] +pub struct SectionAnchor { + pub title: String, + pub timestamp: u64, +} + +impl AnchorTrait for SectionAnchor { + fn entry_type() -> String { + String::from("section_anchor") + } + fn link_to() -> String { + Section::entry_type() + } + fn link_type() -> String { + "section_anchor->section".to_owned() + } +} + +impl SectionAnchor { + pub fn new(title: String, timestamp: u64) -> Self { + SectionAnchor { + title:title, + timestamp: timestamp, + } + } +} + +pub fn section_anchor_def() -> ValidatingEntryType { + entry!( + name: SectionAnchor::entry_type(), + sharing: Sharing::Public, + validation_package: || { + hdk::ValidationPackageDefinition::Entry + }, + validation: | validation_data: hdk::EntryValidationData| { + match validation_data{ + EntryValidationData::Create { .. } => { + Ok(()) + }, + EntryValidationData::Modify { .. } => { + Ok(()) + }, + EntryValidationData::Delete { .. } => { + Ok(()) + } + } + }, + links:[ + // link that connects SectionAnchor to the latest Section entry + to!( + SectionAnchor::link_to(), + link_type: SectionAnchor::link_type(), + validation_package:||{ + hdk::ValidationPackageDefinition::Entry + }, + validation:|_validation_data: hdk::LinkValidationData|{ + Ok(()) + } + ) + ] + ) +} \ No newline at end of file diff --git a/dna/course/zomes/courses/code/src/section/entry.rs b/dna/course/zomes/courses/code/src/section/entry.rs new file mode 100644 index 0000000..595c707 --- /dev/null +++ b/dna/course/zomes/courses/code/src/section/entry.rs @@ -0,0 +1,57 @@ +use hdk::{ + entry_definition::ValidatingEntryType, + holochain_core_types::{dna::entry_types::Sharing, validation::EntryValidationData}, + holochain_json_api::{error::JsonError, json::JsonString}, + holochain_persistence_api::cas::content::Address, +}; +use holochain_entry_utils::HolochainEntry; + +#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone)] +pub struct Section { + pub title: String, + pub timestamp: u64, + pub anchor_address: Address, +} + +impl Section { + pub fn new( + title: String, + timestamp: u64, + anchor_address: Address, + ) -> Self { + title: title, + timestamp: timestamp, + anchor_address: anchor_address, + } +} + +impl HolochainEntry for Section { + fn entry_type() -> String { + String::from("course") + } +} + +// Holochain entry definition for Section +pub fn section_entry_def() -> ValidatingEntryType { + entry!( + name: Section::entry_type(), + sharing: Sharing::Public, + validation_package: || { + hdk::ValidationPackageDefinition::Entry + }, + validation: | validation_data: hdk::EntryValidationData
| { + match validation_data { + EntryValidationData::Create { .. } => { + Ok(()) + }, + EntryValidationData::Modify { .. } => { + Ok(()) + }, + EntryValidationData::Delete { .. } => { + Ok(()) + } + } + }, + links: [] + ) +} diff --git a/dna/course/zomes/courses/code/src/section/mod.rs b/dna/course/zomes/courses/code/src/section/mod.rs new file mode 100644 index 0000000..4a7779e --- /dev/null +++ b/dna/course/zomes/courses/code/src/section/mod.rs @@ -0,0 +1,2 @@ +pub mod anchor; +pub mod entry;