admin: add route to handle quiz

This commit is contained in:
nemunaire 2017-12-17 02:50:01 +01:00
commit 48e6ba7861
2 changed files with 40 additions and 1 deletions

View file

@ -187,6 +187,29 @@ func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (
}
}
func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exercice = ex
return nil,nil
})(ps, body)
if qid, err := strconv.Atoi(string(ps.ByName("qid"))); err != nil {
return nil, err
} else if mcqs, err := exercice.GetMCQ(); err != nil {
return nil, err
} else {
for _, mcq := range mcqs {
if (mcq.Id == int64(qid)) {
return f(mcq, exercice, body)
}
}
return nil, errors.New("Unable to find the requested key")
}
}
}
func fileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice