Exemplo n.º 1
0
func GetShowcase(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var err error
	var show showcase.Showcase

	if show.ID, err = strconv.Atoi(params["id"]); err != nil {
		apierror.GenerateError("Trouble getting testimonial ID", err, rw, req)
	}
	if err := show.Get(dtx); err != nil {
		apierror.GenerateError("Trouble getting testimonial", err, rw, req)
	}
	return encoding.Must(enc.Encode(show))
}
Exemplo n.º 2
0
func Save(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var show showcase.Showcase
	var err error
	idStr := params["id"]
	if idStr != "" {
		show.ID, err = strconv.Atoi(idStr)
		err = show.Get(dtx)
		if err != nil {
			apierror.GenerateError("Trouble getting testimonial", err, rw, req)
		}
	}
	//json
	requestBody, err := ioutil.ReadAll(req.Body)
	if err != nil {
		apierror.GenerateError("Trouble reading request body for saving testimonial", err, rw, req)
	}
	err = json.Unmarshal(requestBody, &show)
	if err != nil {
		apierror.GenerateError("Trouble unmarshalling request body for saving testimonial", err, rw, req)
	}
	//create or update
	if show.ID > 0 {
		err = show.Update()
	} else {
		err = show.Create()
	}

	if err != nil {
		apierror.GenerateError("Trouble saving testimonial", err, rw, req)
	}
	return encoding.Must(enc.Encode(show))
}
Exemplo n.º 3
0
func Delete(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params) string {
	var err error
	var a showcase.Showcase

	idStr := params["id"]

	id, err := strconv.Atoi(idStr)
	if err != nil {
		apierror.GenerateError("Trouble getting testimonial ID", err, rw, req)
	}
	a.ID = id
	err = a.Delete()
	if err != nil {
		apierror.GenerateError("Trouble deleting testimonial", err, rw, req)
	}

	return encoding.Must(enc.Encode(a))
}