func ServeCastQuestionVote(store datastores.AnswerStoreServices) m.HandlerFunc { return func(c *m.Context, w http.ResponseWriter, r *http.Request) { vote := 1 urlParams := mux.Vars(r) if urlParams["vote"] == "downvote" { vote = -1 } voteRecipient, err, statusCode := store.CastVote(urlParams["questionID"], vote) if err != nil { http.Error(w, err.Error(), statusCode) } rep, err := c.RepStore.FindRep(urlParams["category"], voteRecipient) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } if rep <= MAX_REP { c.RepStore.UpdateRep(urlParams["category"], voteRecipient, 1) } err, statusCode = store.AssessAnswers(urlParams["questionID"]) if err != nil { http.Error(w, err.Error(), statusCode) } } }
func ServeCastAnswerVote(store datastores.AnswerStoreServices) m.HandlerFunc { return func(c *m.Context, w http.ResponseWriter, r *http.Request) { routeVars := mux.Vars(r) /* if !store.IsCategoryRegistered(routeVars["category"]) { http.Error(w, "The provided category does not exist", http.StatusBadRequest) return } */ vote := 1 if routeVars["vote"] == "downvote" { vote = -1 } voteRecipient, err, statusCode := store.CastVote(routeVars["answerID"], vote) if err != nil { http.Error(w, err.Error(), statusCode) return } rep, err := c.RepStore.FindRep(routeVars["category"], voteRecipient) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } if rep <= MAX_REP { err = c.RepStore.UpdateRep(routeVars["cateogry"], c.UserID, vote) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } } err, statusCode = store.AssessAnswers(routeVars["answerID"]) if err != nil { http.Error(w, err.Error(), statusCode) return } } }