admin: Can list independant exercices as theme

This commit is contained in:
nemunaire 2025-03-27 16:25:48 +01:00
parent d26333c5e2
commit 5e262b75a3
3 changed files with 27 additions and 8 deletions

View file

@ -70,13 +70,17 @@ func ThemeHandler(c *gin.Context) {
return
}
theme, err := fic.GetTheme(thid)
if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Theme not found"})
return
}
if thid == 0 {
c.Set("theme", &fic.Theme{Name: "Exercices indépendants", Path: sync.StandaloneExercicesDirectory})
} else {
theme, err := fic.GetTheme(thid)
if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Theme not found"})
return
}
c.Set("theme", theme)
c.Set("theme", theme)
}
c.Next()
}
@ -127,6 +131,10 @@ func listThemes(c *gin.Context) {
return
}
if has, _ := fic.HasStandaloneExercice(); has {
themes = append([]*fic.Theme{&fic.Theme{Name: "Exercices indépendants", Path: sync.StandaloneExercicesDirectory}}, themes...)
}
c.JSON(http.StatusOK, themes)
}