admin: Reexpose themed exercices_stats.json
Lost in 8b3fbdb64a522d406d182bda5550d7c4964e0098
This commit is contained in:
parent
c7fc18bfb4
commit
0c45b52e04
@ -48,6 +48,8 @@ func declareThemesRoutes(router *gin.RouterGroup) {
|
||||
apiThemesRoutes.PUT("", updateTheme)
|
||||
apiThemesRoutes.DELETE("", deleteTheme)
|
||||
|
||||
apiThemesRoutes.GET("/exercices_stats.json", getThemedExercicesStats)
|
||||
|
||||
declareExercicesRoutes(apiThemesRoutes)
|
||||
|
||||
// Remote
|
||||
@ -117,18 +119,6 @@ func bindingFiles(c *gin.Context) {
|
||||
c.String(http.StatusOK, ret)
|
||||
}
|
||||
|
||||
func getExercice(args []string) (*fic.Exercice, error) {
|
||||
if tid, err := strconv.ParseInt(string(args[0]), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if theme, err := fic.GetTheme(tid); err != nil {
|
||||
return nil, err
|
||||
} else if eid, err := strconv.Atoi(string(args[1])); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return theme.GetExercice(eid)
|
||||
}
|
||||
}
|
||||
|
||||
func listThemes(c *gin.Context) {
|
||||
themes, err := fic.GetThemes()
|
||||
if err != nil {
|
||||
@ -243,21 +233,25 @@ func deleteTheme(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, true)
|
||||
}
|
||||
|
||||
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
|
||||
func getThemedExercicesStats(c *gin.Context) {
|
||||
theme := c.MustGet("theme").(*fic.Theme)
|
||||
|
||||
exercices, err := theme.GetExercices()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to fetch exercices: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
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(),
|
||||
})
|
||||
}
|
||||
c.JSON(http.StatusOK, ret)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user