qa: New service to handle QA testing by students
This commit is contained in:
parent
a0155c6deb
commit
a237936feb
37 changed files with 1476 additions and 0 deletions
36
qa/api/exercice.go
Normal file
36
qa/api/exercice.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
router.GET("/api/exercices/", apiHandler(listExercices))
|
||||
|
||||
router.GET("/api/exercices/:eid", apiHandler(exerciceHandler(showExercice)))
|
||||
}
|
||||
|
||||
func exerciceHandler(f func(QAUser, fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(u QAUser, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if eid, err := strconv.ParseInt(string(ps.ByName("eid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if exercice, err := fic.GetExercice(eid); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return f(u, exercice, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func listExercices(_ QAUser, _ httprouter.Params, body []byte) (interface{}, error) {
|
||||
// List all exercices
|
||||
return fic.GetExercices()
|
||||
}
|
||||
|
||||
func showExercice(_ QAUser, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice, nil
|
||||
}
|
||||
Reference in a new issue