Example #1
0
// PostHandler ccreates a new comment given a bunch of params
func PostHandler(w http.ResponseWriter, req *http.Request) {
	params, err := parseCommentParams(w, req)
	if err != nil {
		friendlyErr := errors.New("Problem parsing parameters. (" + err.Error() + ")")
		helpers.SendError(http.StatusBadRequest, friendlyErr, w)
		return
	}

	err = querier.InsertComment(params.PostID, params.ParentID, params.Comment)
	if err != nil {
		friendlyErr := errors.New("Insert error. (" + err.Error() + ")")
		helpers.SendError(http.StatusBadRequest, friendlyErr, w)
		return
	}

	resp := models.GenericResponse{200, "Comment successful"}
	json.NewEncoder(w).Encode(resp)
}
Example #2
0
func InsertSubHandler(w http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	sub := req.PostFormValue("sub_name")
	err := querier.InsertSub(sub)
	if err != nil {
		friendlyErr := errors.New("Insert error. (" + err.Error() + ")")
		helpers.SendError(http.StatusBadRequest, friendlyErr, w)
		return
	}
	resp := models.GenericResponse{200, "Comment successful"}
	json.NewEncoder(w).Encode(resp)

}