func JudgeSubmission(w http.ResponseWriter, r *http.Request) { me, _ := context.Get(r, "me").(*data.Account) if me == nil || (me.Level != data.Judge && me.Level != data.Administrator) { http.Error(w, "", http.StatusForbidden) return } vars := mux.Vars(r) id, err := strconv.ParseInt(vars["id"], 10, 64) catch(err) subm, err := data.GetSubmission(id) catch(err) subm.Reset() err = subm.Put() catch(err) hub.Send([]interface{}{"SYNC", "submissions", subm.Id}) exec := &data.Execution{ SubmissionId: subm.Id, Apply: true, } err = exec.Put() catch(err) belt.Push(exec) err = data.NewActivity(me, fmt.Sprintf("judged submission %d", subm.Id)).Put() catch(err) hub.Send([]interface{}{"SYNC", "activities"}) }
func CreateExecution(w http.ResponseWriter, r *http.Request) { me, _ := context.Get(r, "me").(*data.Account) if me == nil || (me.Level != data.Judge && me.Level != data.Administrator) { http.Error(w, "", http.StatusForbidden) return } body := struct { SubmissionId int64 `json:"submissionId"` }{} err := json.NewDecoder(r.Body).Decode(&body) catch(err) subm, err := data.GetSubmission(body.SubmissionId) catch(err) exec := &data.Execution{ SubmissionId: subm.Id, } err = exec.Put() catch(err) belt.Push(exec) err = json.NewEncoder(w).Encode(exec) catch(err) err = data.NewActivity(me, fmt.Sprintf("created execution %d for submission %d", exec.Id, subm.Id)).Put() catch(err) hub.Send([]interface{}{"SYNC", "activities"}) }
func CreateSubmission(w http.ResponseWriter, r *http.Request) { me, _ := context.Get(r, "me").(*data.Account) if me == nil { http.Error(w, "", http.StatusForbidden) return } body := struct { ProblemId int64 `json:"problemId"` Language string `json:"language"` Source string `json:"source"` }{} err := json.NewDecoder(r.Body).Decode(&body) catch(err) prob, err := data.GetProblem(body.ProblemId) catch(err) key, err := data.Blobs.Put("", strings.NewReader(body.Source)) catch(err) subm := &data.Submission{ AuthorId: me.Id, ProblemId: prob.Id, Language: body.Language, SourceKey: string(key), } err = subm.Put() catch(err) err = json.NewEncoder(w).Encode(subm) catch(err) hub.Send([]interface{}{"SYNC", "submissions"}) err = data.NewActivity(me, fmt.Sprintf("created submission %d", subm.Id)).Put() catch(err) hub.Send([]interface{}{"SYNC", "activities"}) if prob.Judge == "automatic" { exec := &data.Execution{ SubmissionId: subm.Id, Apply: true, } err = exec.Put() catch(err) belt.Push(exec) } }