admin: new route to fill URLIds if they are not defined
This commit is contained in:
parent
8ae4d1c42f
commit
6d1ef0f51c
4 changed files with 56 additions and 0 deletions
|
@ -50,6 +50,14 @@ func init() {
|
|||
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil })))
|
||||
router.POST("/api/sync/exercices/:eid/quiz", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceMCQ(sync.GlobalImporter, exercice), nil })))
|
||||
|
||||
router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
if exercice.FixURLId() {
|
||||
return exercice.Update()
|
||||
}
|
||||
return 0, nil
|
||||
})))
|
||||
}
|
||||
|
||||
func listExercices(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
|
|
|
@ -59,6 +59,38 @@ func init() {
|
|||
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil })))
|
||||
router.POST("/api/sync/themes/:thid/exercices/:eid/quiz", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceMCQ(sync.GlobalImporter, exercice), nil })))
|
||||
|
||||
router.POST("/api/sync/themes/:thid/fixurlid", apiHandler(themeHandler(
|
||||
func(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
if theme.FixURLId() {
|
||||
return theme.Update()
|
||||
}
|
||||
return 0, nil
|
||||
})))
|
||||
router.POST("/api/sync/fixurlids", apiHandler(fixAllURLIds))
|
||||
}
|
||||
|
||||
func fixAllURLIds(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||
nbFix := 0
|
||||
if themes, err := fic.GetThemes(); err == nil {
|
||||
for _, theme := range themes {
|
||||
if theme.FixURLId() {
|
||||
theme.Update()
|
||||
nbFix += 1
|
||||
}
|
||||
|
||||
if exercices, err := theme.GetExercices(); err == nil {
|
||||
for _, exercice := range exercices {
|
||||
if exercice.FixURLId() {
|
||||
exercice.Update()
|
||||
nbFix += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nbFix, nil
|
||||
}
|
||||
|
||||
func bindingFiles(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
|
|
Reference in a new issue