admin: Implement theme modification through PATCH

This commit is contained in:
nemunaire 2016-01-22 17:36:18 +01:00
parent ad6199269b
commit 61dc38c09c

View File

@ -11,6 +11,7 @@ import (
var ApiThemesRouting = map[string]DispatchFunction{
"GET": listTheme,
"PATCH": updateTheme,
"POST": creationTheme,
"DELETE": deletionTheme,
}
@ -134,6 +135,40 @@ func creationTheme(args []string, body []byte) (interface{}, error) {
}
}
func updateTheme(args []string, body []byte) (interface{}, error) {
if len(args) == 2 {
// Update an exercice
var ue fic.Exercice
if err := json.Unmarshal(body, &ue); err != nil {
return nil, err
}
if len(ue.Title) == 0 {
return nil, errors.New("Exercice's title not filled")
}
if _, err := ue.Update(); err != nil {
return nil, err
}
return ue, nil
} else if len(args) == 1 {
// Update a theme
var ut fic.Theme
if err := json.Unmarshal(body, &ut); err != nil {
return nil, err
}
if len(ut.Name) == 0 {
return nil, errors.New("Theme's name not filled")
}
return ut.Update()
} else {
return nil, nil
}
}
func deletionTheme(args []string, body []byte) (interface{}, error) {
if len(args) == 2 {
if exercice, err := getExercice(args); err != nil {