admin: add route to handle quiz
This commit is contained in:
parent
830dacd6f5
commit
48e6ba7861
2 changed files with 40 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Reference in a new issue