Ejemplo n.º 1
0
// Create constructs a new event from the data in the POST body
func (h *Handler) Create(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	e := Event{}

	if err := jsonUtils.Decode(r.Body, &e); err != nil {
		jsonUtils.Error(w, http.StatusBadRequest, err.Error())
		return
	}

	if err := e.insert(); err != nil {
		jsonUtils.Error(w, http.StatusInternalServerError, err.Error())
		return
	}

	jsonUtils.Output(w, 201, e)
}
Ejemplo n.º 2
0
// Create is a REST API for creating a new subscription, based on the JSON payload
func (h *Handler) Create(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	subscription := Subscription{}

	if err := jsonUtils.Decode(r.Body, &subscription); err != nil {
		jsonUtils.Error(w, http.StatusBadRequest, err.Error())
		return
	}

	if err := subscription.insert(); err != nil {
		jsonUtils.Error(w, http.StatusBadRequest, err.Error())
		return
	}

	jsonUtils.Output(w, 201, subscription)
}