admin: New page to list tags
This commit is contained in:
parent
a6adc1ac8c
commit
80917ae436
5 changed files with 84 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
func declareGlobalExercicesRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/resolutions.json", exportResolutionMovies)
|
||||
router.GET("/exercices_stats.json", getExercicesStats)
|
||||
router.GET("/tags", listTags)
|
||||
}
|
||||
|
||||
func declareExercicesRoutes(router *gin.RouterGroup) {
|
||||
|
|
@ -225,6 +226,32 @@ func listExercices(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func listTags(c *gin.Context) {
|
||||
exercices, err := fic.GetExercices()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
ret := map[string][]*fic.Exercice{}
|
||||
for _, exercice := range exercices {
|
||||
tags, err := exercice.GetTags()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
for _, t := range tags {
|
||||
if _, ok := ret[t]; !ok {
|
||||
ret[t] = []*fic.Exercice{}
|
||||
}
|
||||
|
||||
ret[t] = append(ret[t], exercice)
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, ret)
|
||||
}
|
||||
|
||||
// Generate the csv to export with:
|
||||
// curl -s http://127.0.0.1:8081/api/resolutions.json | jq -r ".[] | [ .theme,.title, @uri \"https://fic.srs.epita.fr/resolution/\\(.videoURI)\" ] | join(\";\")"
|
||||
func exportResolutionMovies(c *gin.Context) {
|
||||
|
|
|
|||
Reference in a new issue