Пример #1
0
func (c ApiV1Questions) Answer(attendId int, num int, answer string) revel.Result {
	var attend models.Attend
	var contest models.Contest
	var question models.Question

	controllers.DB.Where("id = ?", attendId).First(&attend)
	controllers.DB.Model(&attend).Related(&contest)
	n := contest.GetQuestionId(num)

	if err := controllers.DB.First(&question, n).Error; err != nil {
		return c.RenderJson(ErrorResponse{Code: 404, Message: "Invalid id"})
	}

	var r Response
	if answer == question.Answer {
		attend.SetScore(num, 10)
		r = Response{"correct"}
	} else {
		attend.SetScore(num, 0)
		r = Response{"wrong"}
	}
	return c.RenderJson(r)
}
Пример #2
0
func (c ApiV1Contests) Result(attendId int) revel.Result {
	var attend models.Attend
	controllers.DB.Where("id = ?", attendId).First(&attend)

	return c.RenderJson(Response{attend.GetResultScore()})
}