Beispiel #1
0
func setHighlightHandler(v string, w http.ResponseWriter, r *http.Request) {
	// TODO: use and enforce PUT
	var arg FetchCommentsEnv
	err := util.StringToJSON(v, &arg)
	if err != nil {
		panic(err)
	}
	var req struct {
		ReaderId string `json:"readerId"`
	}
	err = util.ReaderToJSON(r.Body, int(r.ContentLength), &req)
	if err != nil {
		panic(err)
	}
	now := time.Now().Unix()
	hl := &model.Highlight{
		arg.AppId,
		model.ReviewerId(req.ReaderId),
		arg.ReviewerId,
		arg.ReviewerName,
		float64(now),
	}
	err = dept.SetHighlight(hl)
	if err != nil {
		panic(err)
	}
	w.WriteHeader(200)
}
Beispiel #2
0
func setScoreHandler(key string, w http.ResponseWriter, r *http.Request) {
	var arg FetchCommentsEnv
	err := util.StringToJSON(key, &arg)
	if err != nil {
		log.Printf("FATAL ERROR decoding closure %v in setScoreHandler", key)
		w.WriteHeader(500)
		return
	}
	if r.Method != "POST" {
		log.Printf("%v SECURITY ERROR %v trying to %v to %v", r.RemoteAddr,
			arg.ReviewerId, r.Method, r.URL)
		w.WriteHeader(http.StatusBadRequest)
		r.Close = true
		return
	}
	var req struct {
		Label string `json:"label"`
		Score *int   `json:"score"`
	}
	err = util.ReaderToJSON(r.Body, int(r.ContentLength), &req)
	if err != nil && req.Label != "score" {
		w.WriteHeader(http.StatusBadRequest)
		r.Close = true
		return
	}
	score := &model.Score{arg.AppId, arg.ReviewerId, req.Label, req.Score}
	err = dept.SetScore(score)
	if err != nil {
		w.WriteHeader(500)
		r.Close = true
		log.Printf("%v ERROR SetScore(%v)", r.RemoteAddr, score)
		return
	}
	w.WriteHeader(200)
	return
}