diff --git a/admin/api/exercice.go b/admin/api/exercice.go index a1ab5153..6d698641 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -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() }