Beispiel #1
0
// check the output
func (c *Code) Check(id int64) revel.Result {
	s := models.Source{}
	has, err := engine.Id(id).Get(&s)
	if err != nil {
		log.Println(err)
	}
	data := make(map[string]interface{})
	if !has {
		data[STATUS] = false
		data[ERROR] = "not exist!"
		return c.RenderJson(data)
	}
	r, e := s.Check()
	if e != nil || s.Status != models.WrongAnswer {
		data[STATUS] = false
		if e != nil {
			data[ERROR] = e.Error()
		} else {
			data[ERROR] = "not wrong answer"
		}
		return c.RenderJson(data)
	} else {
		data[STATUS] = true
		data[REPORT] = r
		return c.RenderJson(data)
	}
}
Beispiel #2
0
//get source code
func (c *Code) View(id int64) revel.Result {
	s := models.Source{}
	has, err := engine.Id(id).Get(&s)
	if err != nil {
		log.Println(err)
	}
	data := make(map[string]interface{})
	if !has {
		data[STATUS] = false
		data[ERROR] = "not exits"
		return c.RenderJson(data)
	}
	code, err := s.View()
	if err != nil {
		data[STATUS] = false
		data[ERROR] = err.Error()
	}
	data[STATUS] = true
	data[CODE] = code
	return c.RenderJson(data)
}