func destroyCode(ctx appengine.Context, user *models.User, r *http.Request) *ActionResponse { id, _ := strconv.ParseInt(r.FormValue("id"), 10, 64) removed, err := models.DestroyCodeBy(ctx, id) if removed { return (&ActionResponse{ Code: http.StatusNoContent, RenderText: "", }).AsJson() } else { return (&ActionResponse{ Code: http.StatusNotFound, RenderText: createApiError(err).AsJson(), }).AsJson() } }
func (c *AppController) DestroyCode(w http.ResponseWriter, r *http.Request, session *sessions.Session) *ActionResponse { ctx := appengine.NewContext(r) id, _ := strconv.ParseInt(r.FormValue("id"), 10, 64) if id == 0 { c.AddNotice(session, "Request does not include any object id") } else { removed, err := models.DestroyCodeBy(ctx, id) if removed { c.AddNotice(session, "Successfully removed!") } else { fmt.Fprintf(w, "Failed to delete: %s", err.Error()) } } return &ActionResponse{RedirectTo: "/codes"} }