admin: add some stats about exercices
This commit is contained in:
parent
007efc6118
commit
5df1cc6e93
5 changed files with 104 additions and 8 deletions
|
@ -25,6 +25,8 @@ func init() {
|
|||
router.GET("/api/themes/:thid/exercices", apiHandler(themeHandler(listThemedExercices)))
|
||||
router.POST("/api/themes/:thid/exercices", apiHandler(themeHandler(createExercice)))
|
||||
|
||||
router.GET("/api/themes/:thid/exercices_stats.json", apiHandler(themeHandler(getThemedExercicesStats)))
|
||||
|
||||
router.GET("/api/themes/:thid/exercices/:eid", apiHandler(exerciceHandler(showExercice)))
|
||||
router.PUT("/api/themes/:thid/exercices/:eid", apiHandler(exerciceHandler(updateExercice)))
|
||||
router.DELETE("/api/themes/:thid/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
|
||||
|
@ -205,3 +207,22 @@ func updateTheme(theme fic.Theme, body []byte) (interface{}, error) {
|
|||
func deleteTheme(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
return theme.Delete()
|
||||
}
|
||||
|
||||
func getThemedExercicesStats(theme fic.Theme, body []byte) (interface{}, error) {
|
||||
if exercices, err := theme.GetExercices(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
ret := []exerciceStats{}
|
||||
for _, e := range exercices {
|
||||
ret = append(ret, exerciceStats{
|
||||
IdExercice: e.Id,
|
||||
TeamTries: e.TriedTeamCount(),
|
||||
TotalTries: e.TriedCount(),
|
||||
SolvedCount: e.SolvedCount(),
|
||||
FlagSolved: e.FlagSolved(),
|
||||
MCQSolved: e.MCQSolved(),
|
||||
})
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue