admin: add a new route to generate a file for movie links

This commit is contained in:
nemunaire 2019-01-25 16:31:48 +01:00
parent 81502ce238
commit caa0511023
1 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import (
func init() {
router.GET("/api/exercices/", apiHandler(listExercices))
router.GET("/api/resolutions.json", apiHandler(exportResolutionMovies))
router.GET("/api/exercices/:eid", apiHandler(exerciceHandler(showExercice)))
router.PUT("/api/exercices/:eid", apiHandler(exerciceHandler(updateExercice)))
@ -85,6 +86,28 @@ func listExercices(_ httprouter.Params, body []byte) (interface{}, error) {
return fic.GetExercices()
}
// 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(_ httprouter.Params, body []byte) (interface{}, error) {
if exercices, err := fic.GetExercices(); err != nil {
return nil, err
} else {
export := []map[string]string{}
for _, exercice := range exercices {
if theme, err := fic.GetTheme(exercice.IdTheme); err != nil {
return nil, err
} else {
export = append(export, map[string]string{
"videoURI": exercice.VideoURI,
"theme": theme.Name,
"title": exercice.Title,
})
}
}
return export, nil
}
}
func listExerciceFiles(exercice fic.Exercice, body []byte) (interface{}, error) {
return exercice.GetFiles()
}