Multiple hints
This commit is contained in:
parent
22e8937879
commit
25bf34e82c
9 changed files with 217 additions and 35 deletions
|
@ -115,3 +115,22 @@ func createExerciceKey(theme fic.Theme, exercice fic.Exercice, args map[string]s
|
|||
|
||||
return exercice.AddRawKey(uk.Name, uk.Key)
|
||||
}
|
||||
|
||||
type uploadedHint struct {
|
||||
Title string
|
||||
Content string
|
||||
Cost int64
|
||||
}
|
||||
|
||||
func createExerciceHint(theme fic.Theme, exercice fic.Exercice, args map[string]string, body []byte) (interface{}, error) {
|
||||
var uh uploadedHint
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(uh.Content) == 0 {
|
||||
return nil, errors.New("Hint's content not filled")
|
||||
}
|
||||
|
||||
return exercice.AddHint(uh.Title, uh.Content, uh.Cost)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ func init() {
|
|||
rtef.Methods("GET").HandlerFunc(apiHandler(themeHandler(themedExerciceHandler(listThemedExerciceFiles))))
|
||||
rtef.Methods("POST").HandlerFunc(apiHandler(themeHandler(themedExerciceHandler(createExerciceFile))))
|
||||
|
||||
rteh := rte.Path("/hints").Subrouter()
|
||||
rteh.Methods("GET").HandlerFunc(apiHandler(themeHandler(themedExerciceHandler(listThemedExerciceHints))))
|
||||
rteh.Methods("POST").HandlerFunc(apiHandler(themeHandler(themedExerciceHandler(createExerciceHint))))
|
||||
|
||||
rtek := rte.Path("/keys").Subrouter()
|
||||
rtek.Methods("GET").HandlerFunc(apiHandler(themeHandler(themedExerciceHandler(listThemedExerciceKeys))))
|
||||
rtek.Methods("POST").HandlerFunc(apiHandler(themeHandler(themedExerciceHandler(createExerciceKey))))
|
||||
|
@ -86,6 +90,10 @@ func listThemedExerciceFiles(theme fic.Theme, exercice fic.Exercice, args map[st
|
|||
return exercice.GetFiles()
|
||||
}
|
||||
|
||||
func listThemedExerciceHints(theme fic.Theme, exercice fic.Exercice, args map[string]string, body []byte) (interface{}, error) {
|
||||
return exercice.GetHints()
|
||||
}
|
||||
|
||||
func listThemedExerciceKeys(theme fic.Theme, exercice fic.Exercice, args map[string]string, body []byte) (interface{}, error) {
|
||||
return exercice.GetKeys()
|
||||
}
|
||||
|
|
Reference in a new issue