Skip to content

Instantly share code, notes, and snippets.

@nilslice
Last active February 22, 2017 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilslice/297ce9d7eb18c58bab375f0844f4cd19 to your computer and use it in GitHub Desktop.
Save nilslice/297ce9d7eb18c58bab375f0844f4cd19 to your computer and use it in GitHub Desktop.
package content
import (
"github.com/ponzu-cms/ponzu/management/editor"
"github.com/ponzu-cms/ponzu/system/item"
)
type Review struct {
item.Item
Title string `json:"title"`
Body string `json:"body"`
Rating int `json:"rating"`
Tags []string `json:"tags"`
}
// ... remainder of the Review code for MarshalEditor, etc.
// generated from $ ponzu gen model:java review
// generated from $ ponzu gen model:js review
var contentAPI = '//localhost:8080/api/content?type=Review'
var contentsAPI = '//localhost:8080/api/contents?type=Review'
var Review = functiion(data) {
this.title = data.title;
this.body = data.body;
this.rating = data.rating;
this.tags = data.tags;
this.slug = data.slug || null; // belongs to item.Item
this.timestamp = data.timestamp || null; // belongs to item.Item
// ... and so on, or this.data = data...
}
Review.prototype.getByID = function(id) {
// return XHR result/promise for contentAPI+'&id='+id
}
Review.prototype.getAll = function(options) {
// options = {count:-1, offset:0, order:'desc'}
// return XHR result/promise for contentsAPI
}
Review.prototype.getBySlug = function() {
// return XHR result/promise for contentAPI+'&slug='+this.slug
}
Review.prototype.send = function() {
// if the type implements api.Externalable, we could add the external endpoint to POST data
/// include only non-item.Item fields, just fields on the belonging exclusively to content type struct
var data = new FormData();
data.append('title', this.title);
data.append('body', this.body);
data.append('rating', this.rating);
data.append('tags', this.tags);
// do xhr POST with data
// return result/promise
}
// generated from $ ponzu gen model:swift review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment