Rename Exercice's Keys as Flags

This commit is contained in:
nemunaire 2018-09-24 10:00:17 +02:00 committed by Pierre-Olivier Mercier
parent f36e1c4e4d
commit d21f3b0b83
18 changed files with 252 additions and 252 deletions

View file

@ -30,11 +30,11 @@ func init() {
router.PUT("/api/exercices/:eid/hints/:hid", apiHandler(hintHandler(updateExerciceHint)))
router.DELETE("/api/exercices/:eid/hints/:hid", apiHandler(hintHandler(deleteExerciceHint)))
router.GET("/api/exercices/:eid/keys", apiHandler(exerciceHandler(listExerciceKeys)))
router.POST("/api/exercices/:eid/keys", apiHandler(exerciceHandler(createExerciceKey)))
router.GET("/api/exercices/:eid/keys/:kid", apiHandler(keyHandler(showExerciceKey)))
router.PUT("/api/exercices/:eid/keys/:kid", apiHandler(keyHandler(updateExerciceKey)))
router.DELETE("/api/exercices/:eid/keys/:kid", apiHandler(keyHandler(deleteExerciceKey)))
router.GET("/api/exercices/:eid/flags", apiHandler(exerciceHandler(listExerciceFlags)))
router.POST("/api/exercices/:eid/flags", apiHandler(exerciceHandler(createExerciceFlag)))
router.GET("/api/exercices/:eid/flags/:kid", apiHandler(flagHandler(showExerciceFlag)))
router.PUT("/api/exercices/:eid/flags/:kid", apiHandler(flagHandler(updateExerciceFlag)))
router.DELETE("/api/exercices/:eid/flags/:kid", apiHandler(flagHandler(deleteExerciceFlag)))
router.GET("/api/exercices/:eid/quiz", apiHandler(exerciceHandler(listExerciceQuiz)))
router.GET("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(showExerciceQuiz)))
@ -50,9 +50,9 @@ func init() {
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceHints(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/exercices/:eid/keys", apiHandler(exerciceHandler(
router.POST("/api/sync/exercices/:eid/flags", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil
return sync.SyncExerciceFlags(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler(
@ -77,8 +77,8 @@ func listExerciceHints(exercice fic.Exercice, body []byte) (interface{}, error)
return exercice.GetHints()
}
func listExerciceKeys(exercice fic.Exercice, body []byte) (interface{}, error) {
return exercice.GetKeys()
func listExerciceFlags(exercice fic.Exercice, body []byte) (interface{}, error) {
return exercice.GetFlags()
}
func listExerciceQuiz(exercice fic.Exercice, body []byte) (interface{}, error) {
@ -188,56 +188,56 @@ func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) {
return hint.Delete()
}
type uploadedKey struct {
type uploadedFlag struct {
Label string
Help string
ICase bool
Key string
Flag string
Hash []byte
}
func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error) {
var uk uploadedKey
func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error) {
var uk uploadedFlag
if err := json.Unmarshal(body, &uk); err != nil {
return nil, err
}
if len(uk.Key) == 0 {
return nil, errors.New("Key not filled")
if len(uk.Flag) == 0 {
return nil, errors.New("Flag not filled")
}
return exercice.AddRawKey(uk.Label, uk.Help, uk.ICase, uk.Key)
return exercice.AddRawFlag(uk.Label, uk.Help, uk.ICase, uk.Flag)
}
func showExerciceKey(key fic.Key, _ fic.Exercice, body []byte) (interface{}, error) {
return key, nil
func showExerciceFlag(flag fic.Flag, _ fic.Exercice, body []byte) (interface{}, error) {
return flag, nil
}
func updateExerciceKey(key fic.Key, exercice fic.Exercice, body []byte) (interface{}, error) {
var uk uploadedKey
func updateExerciceFlag(flag fic.Flag, exercice fic.Exercice, body []byte) (interface{}, error) {
var uk uploadedFlag
if err := json.Unmarshal(body, &uk); err != nil {
return nil, err
}
if len(uk.Label) == 0 {
key.Label = "Flag"
flag.Label = "Flag"
} else {
key.Label = uk.Label
flag.Label = uk.Label
}
key.Help = uk.Help
key.IgnoreCase = uk.ICase
key.Checksum = uk.Hash
flag.Help = uk.Help
flag.IgnoreCase = uk.ICase
flag.Checksum = uk.Hash
if _, err := key.Update(); err != nil {
if _, err := flag.Update(); err != nil {
return nil, err
}
return key, nil
return flag, nil
}
func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, error) {
return key.Delete()
func deleteExerciceFlag(flag fic.Flag, _ fic.Exercice, _ []byte) (interface{}, error) {
return flag.Delete()
}
func showExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, error) {

View file

@ -165,7 +165,7 @@ func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter
}
}
func keyHandler(f func(fic.Key, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
func flagHandler(f func(fic.Flag, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
@ -175,12 +175,12 @@ func keyHandler(f func(fic.Key, fic.Exercice, []byte) (interface{}, error)) func
if kid, err := strconv.Atoi(string(ps.ByName("kid"))); err != nil {
return nil, err
} else if keys, err := exercice.GetKeys(); err != nil {
} else if flags, err := exercice.GetFlags(); err != nil {
return nil, err
} else {
for _, key := range keys {
if key.Id == int64(kid) {
return f(key, exercice, body)
for _, flag := range flags {
if flag.Id == int64(kid) {
return f(flag, exercice, body)
}
}
return nil, errors.New("Unable to find the requested key")

View file

@ -35,8 +35,8 @@ func init() {
router.GET("/api/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(listExerciceHints)))
router.POST("/api/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(createExerciceHint)))
router.GET("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(listExerciceKeys)))
router.POST("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(createExerciceKey)))
router.GET("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(listExerciceFlags)))
router.POST("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(createExerciceFlag)))
// Remote
router.GET("/api/remote/themes", apiHandler(sync.ApiListRemoteThemes))
@ -66,7 +66,7 @@ func init() {
})))
router.POST("/api/sync/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil
return sync.SyncExerciceFlags(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/themes/:thid/fixurlid", apiHandler(themeHandler(

View file

@ -9,5 +9,5 @@ func init() {
}
func showVersion(_ httprouter.Params, body []byte) (interface{}, error) {
return map[string]interface{}{"version": 0.5}, nil
return map[string]interface{}{"version": 0.6}, nil
}