// 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) }
// 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) }
// Show returns the data for a specific feed as JSON func Show(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { f, err := lookup(ps.ByName("id")) if err != nil { jsonUtils.Error(w, http.StatusInternalServerError, err.Error()) return } jsonUtils.Output(w, 200, f) }
// Create constructs a new feed from the data in the POST body func Create(w http.ResponseWriter, r *http.Request, p httprouter.Params) { f := Feed{} decoder := json.NewDecoder(r.Body) err := decoder.Decode(&f) if err != nil { jsonUtils.Error(w, http.StatusBadRequest, err.Error()) return } err = f.insert() if err != nil { jsonUtils.Error(w, http.StatusInternalServerError, err.Error()) return } jsonUtils.Output(w, 201, f) }