func trackCode(ctx appengine.Context, user *models.User, r *http.Request) *ActionResponse {
	id, _ := strconv.ParseInt(r.FormValue("id"), 10, 64)
	updated, err := models.StartTrackingCode(ctx, id)

	if updated {
		return (&ActionResponse{
			Code:       http.StatusNoContent,
			RenderText: "",
		}).AsJson()
	} else {
		return (&ActionResponse{
			Code:       http.StatusNotFound,
			RenderText: createApiError(err).AsJson(),
		}).AsJson()
	}
}
Exemplo n.º 2
0
func (c *AppController) StartTracking(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, "Not available")
	} else {
		updated, err := models.StartTrackingCode(ctx, id)

		if updated == false {
			c.AddNotice(session, fmt.Sprintf("Error: %s", err.Error()))
		} else {
			c.AddNotice(session, "Saved!")
		}
	}

	return &ActionResponse{
		RedirectTo: "/codes",
	}
}