Ejemplo n.º 1
0
func (c *AccountsController) Update(w http.ResponseWriter, r *http.Request) {
	authHeader := r.Header.Get("Authorization")

	account := models.FindAccountByJwt(authHeader)
	if account == nil {
		http.Error(w, "Account not found", http.StatusUnauthorized)
		return
	}

	decoder := json.NewDecoder(r.Body)
	var p UpdateAccountParams
	err := decoder.Decode(&p)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	account.Subdomain = p.Subdomain
	account.Plan = p.Plan
	_, err = models.Update(account)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, Response(account.Serialize()))
}
Ejemplo n.º 2
0
func (c *AccountsController) Show(w http.ResponseWriter, r *http.Request) {
	authHeader := r.Header.Get("Authorization")

	account := models.FindAccountByJwt(authHeader)
	if account == nil {
		http.Error(w, "Account not found", http.StatusUnauthorized)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, Response(account.Serialize()))
}