Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions dna/course/zomes/courses/code/src/content/entry.rs
Original file line number Diff line number Diff line change
@@ -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,
Comment thread
falyhery marked this conversation as resolved.
}

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")
Comment thread
falyhery marked this conversation as resolved.
}
}

// 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<Content>| {
match validation_data {
EntryValidationData::Create { .. } => {
Ok(())
},
EntryValidationData::Modify { .. } => {
Ok(())
},
EntryValidationData::Delete { .. } => {
Ok(())
}
}
},
links: []
)
}
1 change: 1 addition & 0 deletions dna/course/zomes/courses/code/src/content/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod entry;
21 changes: 17 additions & 4 deletions dna/course/zomes/courses/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use hdk_proc_macros::zome;

mod anchor_trait;
mod course;
mod section;
mod content;

#[zome]
mod courses {
Expand Down Expand Up @@ -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()
}
}
62 changes: 62 additions & 0 deletions dna/course/zomes/courses/code/src/section/anchor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#[derive(Serialize, Deserialize, Debug,self::DefaultJson, Clone)]
pub struct SectionAnchor {
Comment thread
falyhery marked this conversation as resolved.
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<SectionAnchor>| {
match validation_data{
EntryValidationData::Create { .. } => {
Ok(())
},
EntryValidationData::Modify { .. } => {
Ok(())
},
EntryValidationData::Delete { .. } => {
Ok(())
}
}
},
links:[
Comment thread
falyhery marked this conversation as resolved.
// 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(())
}
)
]
)
}
57 changes: 57 additions & 0 deletions dna/course/zomes/courses/code/src/section/entry.rs
Original file line number Diff line number Diff line change
@@ -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 {
Comment thread
falyhery marked this conversation as resolved.
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")
Comment thread
falyhery marked this conversation as resolved.
}
}

// 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<Section>| {
match validation_data {
EntryValidationData::Create { .. } => {
Ok(())
},
EntryValidationData::Modify { .. } => {
Ok(())
},
EntryValidationData::Delete { .. } => {
Ok(())
}
}
},
links: []
)
}
2 changes: 2 additions & 0 deletions dna/course/zomes/courses/code/src/section/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod anchor;
pub mod entry;