admin: new route to get exercice stats

This commit is contained in:
nemunaire 2019-02-03 22:48:14 +01:00
commit ee2f65aae7
3 changed files with 57 additions and 0 deletions

View file

@ -22,6 +22,7 @@ func init() {
router.PATCH("/api/exercices/:eid", apiHandler(exerciceHandler(partUpdateExercice)))
router.DELETE("/api/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
router.GET("/api/exercices/:eid/stats", apiHandler(exerciceHandler(getExerciceStats)))
router.GET("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(getExerciceHistory)))
router.DELETE("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(delExerciceHistory)))
@ -136,6 +137,15 @@ func showExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
return exercice, nil
}
func getExerciceStats(exercice fic.Exercice, body []byte) (interface{}, error) {
team_tries, tries := exercice.TriesByTeam()
return map[string]interface{}{
"solved": exercice.SolvedTeams(),
"total_tried": tries,
"team_tries": team_tries,
}, nil
}
func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
return exercice.GetHistory()
}