コード例 #1
0
func updateCateringVote(c web.C, w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	cateringuuid, err := uuid.FromString(c.URLParams["uuid"])
	playeruuid, err := uuid.FromString(c.URLParams["playeruuid"])
	catering, err := caterings.CateringByUUID(cateringuuid)
	if err != nil {
		return &appError{err, "Cant find catering", 404}
	}

	tempInfo := new(caterings.Vote)
	decoder := json.NewDecoder(r.Body)
	if err := decoder.Decode(tempInfo); err != nil {
		return &appError{err, "Invalid JSON", 400}
	}

	if err := catering.RemoveVote(playeruuid); err != nil {
		return &appError{err, "Failed to remove old catering vote when updating", 500}
	}

	if err := catering.AddVote(playeruuid, tempInfo.Score); err != nil {
		return &appError{err, "Failed to add updated catering vote", 500}
	}
	w.WriteHeader(204)
	return nil
}
コード例 #2
0
func getCatering(c web.C, w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	uuid, err := uuid.FromString(c.URLParams["uuid"])
	catering, err := caterings.CateringByUUID(uuid)
	if err != nil {
		return &appError{err, "Cant find catering", 404}
	}
	encoder := json.NewEncoder(w)
	encoder.Encode(catering)
	return nil
}
コード例 #3
0
func updateCateringInfo(c web.C, w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	uuid, err := uuid.FromString(c.URLParams["uuid"])
	catering, err := caterings.CateringByUUID(uuid)
	if err != nil {
		return &appError{err, "Cant find catering", 404}
	}
	tempInfo := new(caterings.Info)
	decoder := json.NewDecoder(r.Body)
	if err := decoder.Decode(tempInfo); err != nil {
		return &appError{err, "Invalid JSON", 400}
	}

	if err := catering.UpdateInfo(*tempInfo); err != nil {
		return &appError{err, "Failed to update catering info", 500}
	}
	w.WriteHeader(204)
	return nil
}