admin: add button and route to reset some parts
This commit is contained in:
parent
7478051425
commit
7597fcfe5b
4 changed files with 65 additions and 0 deletions
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
|
@ -16,6 +17,8 @@ var TeamsDir string
|
|||
func init() {
|
||||
router.GET("/api/settings.json", apiHandler(getSettings))
|
||||
router.PUT("/api/settings.json", apiHandler(saveSettings))
|
||||
|
||||
router.POST("/api/reset", apiHandler(reset))
|
||||
}
|
||||
|
||||
func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
|
@ -38,3 +41,22 @@ func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return config, err
|
||||
}
|
||||
}
|
||||
|
||||
func reset(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
var m map[string]string
|
||||
if err := json.Unmarshal(body, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if t, ok := m["type"]; !ok {
|
||||
return nil, errors.New("Field type not found")
|
||||
} else if t == "teams" {
|
||||
return true, fic.ResetTeams()
|
||||
} else if t == "challenges" {
|
||||
return true, fic.ResetExercices()
|
||||
} else if t == "game" {
|
||||
return true, fic.ResetGame()
|
||||
} else {
|
||||
return nil, errors.New("Unknown reset type")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue