Example #1
0
func (r *TodoResource) Delete(res http.ResponseWriter, req *http.Request) {
	id, err := rest.PathInt(req, "id")
	if err != nil {
		rest.SetBadRequestResponse(res)
		return
	}
	var todo Todo

	db, err := r.Db.Get()
	if err != nil {
		rest.SetInternalServerErrorResponse(res, err)
		return
	}
	if db.First(&todo, id).RecordNotFound() {
		rest.SetNotFoundResponse(res)
		return
	}

	db.Delete(&todo)

	if err := rest.SetNoContentResponse(res); err != nil {
		rest.SetInternalServerErrorResponse(res, err)
		return
	}
}
Example #2
0
func (r *LocationResource) Delete(res http.ResponseWriter, req *http.Request) {
	id, err := rest.PathInt(req, "id")
	if err != nil {
		rest.SetBadRequestResponse(res)
		return
	}
	var location api.Location

	if r.Db.First(&location, id).RecordNotFound() {
		rest.SetNotFoundResponse(res)
		return
	}

	r.Db.Delete(&location)

	if err = r.includeConditions(&location); err != nil {
		rest.SetInternalServerErrorResponse(res, err)
		return
	}
	if err := rest.SetNoContentResponse(res); err != nil {
		rest.SetInternalServerErrorResponse(res, err)
		return
	}
}