Documentation ¶
Index ¶
- func ChooseChild(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
- func DeleteContentResponse(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
- func Exceeded(db *mgo.Database, coll, parent_fieldname, choose_fieldname string, ...) (int, error)
- func IncrementParent(db *mgo.Database, coll, choose_fieldname string, parent_id bson.ObjectId, ...) error
- func IsAuthor(db *mgo.Database, coll, parent_fieldname string, ...) (bson.ObjectId, error)
- func MarkAsChosen(db *mgo.Database, coll, choose_fieldname string, chosen_doc_id bson.ObjectId, ...) error
- func RespondContent(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string, ...) error
- func UnchooseChild(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
- func UnmarkAsChosen(db *mgo.Database, coll, choose_fieldname string, chosen_doc_id bson.ObjectId) error
- func Unvote(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
- func Vote(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChooseChild ¶
func ChooseChild(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
Example:
{ "type": "choose_child", "c": "contents", "choose_fieldname": "accepted", // This field will be set to true when the child document is chosen. "parent_fieldname": "parent", // The name of the field in which the parent's id resides. "max_choices": 1 // Optional, defaults to 1. Describes how many chosen children can exists per parent. }
Gets chosen document to find out parent. Gets parent document, checks if user is the author of it. Return error if not. Sets choose_fieldname to the number of already chosen children + 1 in the chosen document. Increases "has_" + choose_fieldname by 1 in parent document.
func DeleteContentResponse ¶
func DeleteContentResponse(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
We must somehow forbid the deletion of a given ContentResponse, because we have to do these actions at deletion too. TODO: we have to find a solution to this question. Update has no problems, no additional processing needs to be done when updating some fields like title, content, etc. See https://github.com/opesun/hypecms/issues/29 (Or operate with events/hooks?)
Checks if it is possible to delete a response. Checks if the response satisfies the "delete_unless" query, returns error if it does. Deletes response. Decrements parent "counter_fieldname" field by one. Does "update_parent_on_delete_if_child" optional operation.
func Exceeded ¶
func Exceeded(db *mgo.Database, coll, parent_fieldname, choose_fieldname string, parent_id bson.ObjectId, max_choices int) (int, error)
TODO: This could be done by checking the value of "has_" + choose_fieldname in parent.
func IncrementParent ¶
func IsAuthor ¶
func IsAuthor(db *mgo.Database, coll, parent_fieldname string, user_id, chosen_doc_id bson.ObjectId) (bson.ObjectId, error)
Returns an error if user_id is not the author of the parent of the chosen document.
func MarkAsChosen ¶
func RespondContent ¶
func RespondContent(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string, response_content_type_options map[string]interface{}) error
RespondContent could be called "insert child content". Example:
{ "type": "respond", "parent_fieldname": "parent", "counter_fieldname": "replies", "can_delete": true, // Optional, defaults to false "delete_unless": {"$exists": "accepted"} // Optional, possible to delete response, unless this query on the response evaluates to true. "update_parent_on_delete_if_child": [[{"$exists":"accepted"}, // Optional, run this update query on parent. {"$unset": {"has_accepted": 1}}], ...]
}
If the extract module could convert a string to bson.ObjectId we would not need this.
Checks if parent exists. Returns error if not. Inserts new content with the id of the parent. Increments field named "counter_fieldname" in parent.
func UnchooseChild ¶
func UnchooseChild(db *mgo.Database, user, action map[string]interface{}, inp map[string][]string) error
Gets chosen document to find out parent. Gets parent document, checks if user is the author of it. Return error if not. Unsets choose_fieldname in chosen document. Decreases "has_" + choose_fieldname by 1 in parent document.
func UnmarkAsChosen ¶
func Unvote ¶
Checks if unvotes are approved at all. Returns error if not. Checks if vote option is legal. Checks if user indeed voted to that option. Return error if not. Decreases the counter field of the given vote option, and pulls the user_id from the field of the given vote option.
func Vote ¶
Vote options are mutually exclusive. Example:
{ "type": "vote", "c": "contents", "doc_type": "blog", // Optional "can_unvote": true, // Optional, handled as false if unset or set and false. "vote_options": ["like", "dislike"] }
Checks if the vote option sent from UI is legal. Makes sure user have not voted yet, pushes user_id into a field named equal to a member of "vote_options", and increments a field named equal to a member of "vote_options" + "_count".
Types ¶
This section is empty.