From f1e98c3497942b5ed8d1655f21647867765ebfd9 Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:39:15 +0200 Subject: [PATCH 1/6] Entry defs added to lib.rs --- dna/course/zomes/courses/code/src/lib.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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() + } } From c7c0d4365481b5f5895c0f669d5c2dfabb9a1529 Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:46:50 +0200 Subject: [PATCH 2/6] Create mod.rs in Section --- dna/course/zomes/courses/code/src/section/mod.rs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 dna/course/zomes/courses/code/src/section/mod.rs 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; From ddb8c1185fa59c0b6dfe236a0fdf57d0948807c4 Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:47:28 +0200 Subject: [PATCH 3/6] Add entry.rs to Section --- .../zomes/courses/code/src/section/entry.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 dna/course/zomes/courses/code/src/section/entry.rs 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: [] + ) +} From bf0a4051e6fa4267c384e1076a6f0d82d0e600e4 Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:48:10 +0200 Subject: [PATCH 4/6] Add anchor.rs to Section --- .../zomes/courses/code/src/section/anchor.rs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 dna/course/zomes/courses/code/src/section/anchor.rs 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 From 61c9c3d1aa94522740281fe54d70613385962c5c Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:49:23 +0200 Subject: [PATCH 5/6] Create mod.rs in Content --- dna/course/zomes/courses/code/src/content/mod.rs | 1 + 1 file changed, 1 insertion(+) create mode 100644 dna/course/zomes/courses/code/src/content/mod.rs 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; From 0082d7d5ed3c9a0778fda0788cb7542b5012b1bc Mon Sep 17 00:00:00 2001 From: falyhery <32633685+falyhery@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:50:14 +0200 Subject: [PATCH 6/6] Add entry.rs to Content --- .../zomes/courses/code/src/content/entry.rs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 dna/course/zomes/courses/code/src/content/entry.rs 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: [] + ) +}