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.PUT("", updateTheme)
|
||||||
apiThemesRoutes.DELETE("", deleteTheme)
|
apiThemesRoutes.DELETE("", deleteTheme)
|
||||||
|
|
||||||
|
apiThemesRoutes.GET("/exercices_stats.json", getThemedExercicesStats)
|
||||||
|
|
||||||
declareExercicesRoutes(apiThemesRoutes)
|
declareExercicesRoutes(apiThemesRoutes)
|
||||||
|
|
||||||
// Remote
|
// Remote
|
||||||
@ -117,18 +119,6 @@ func bindingFiles(c *gin.Context) {
|
|||||||
c.String(http.StatusOK, ret)
|
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) {
|
func listThemes(c *gin.Context) {
|
||||||
themes, err := fic.GetThemes()
|
themes, err := fic.GetThemes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -243,21 +233,25 @@ func deleteTheme(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, true)
|
c.JSON(http.StatusOK, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getThemedExercicesStats(theme *fic.Theme, body []byte) (interface{}, error) {
|
func getThemedExercicesStats(c *gin.Context) {
|
||||||
if exercices, err := theme.GetExercices(); err != nil {
|
theme := c.MustGet("theme").(*fic.Theme)
|
||||||
return nil, err
|
|
||||||
} else {
|
exercices, err := theme.GetExercices()
|
||||||
ret := []exerciceStats{}
|
if err != nil {
|
||||||
for _, e := range exercices {
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to fetch exercices: %s", err.Error())})
|
||||||
ret = append(ret, exerciceStats{
|
return
|
||||||
IdExercice: e.Id,
|
|
||||||
TeamTries: e.TriedTeamCount(),
|
|
||||||
TotalTries: e.TriedCount(),
|
|
||||||
SolvedCount: e.SolvedCount(),
|
|
||||||
FlagSolved: e.FlagSolved(),
|
|
||||||
MCQSolved: e.MCQSolved(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return ret, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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