admin: can perform mass editing on exercices
This commit is contained in:
parent
1166a925fe
commit
6b54704d59
4 changed files with 97 additions and 9 deletions
|
|
@ -17,6 +17,7 @@ func init() {
|
|||
|
||||
router.GET("/api/exercices/:eid", apiHandler(exerciceHandler(showExercice)))
|
||||
router.PUT("/api/exercices/:eid", apiHandler(exerciceHandler(updateExercice)))
|
||||
router.PATCH("/api/exercices/:eid", apiHandler(exerciceHandler(partUpdateExercice)))
|
||||
router.DELETE("/api/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
|
||||
|
||||
router.GET("/api/exercices/:eid/files", apiHandler(exerciceHandler(listExerciceFiles)))
|
||||
|
|
@ -116,6 +117,51 @@ func updateExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
|||
return ue, nil
|
||||
}
|
||||
|
||||
func partUpdateExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
var ue fic.Exercice
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(ue.Title) > 0 {
|
||||
exercice.Title = ue.Title
|
||||
}
|
||||
|
||||
if len(ue.URLId) > 0 {
|
||||
exercice.URLId = ue.URLId
|
||||
}
|
||||
|
||||
if len(ue.Statement) > 0 {
|
||||
exercice.Statement = ue.Statement
|
||||
}
|
||||
|
||||
if len(ue.Overview) > 0 {
|
||||
exercice.Overview = ue.Overview
|
||||
}
|
||||
|
||||
if ue.Depend != nil {
|
||||
exercice.Depend = ue.Depend
|
||||
}
|
||||
|
||||
if ue.Gain != 0 {
|
||||
exercice.Gain = ue.Gain
|
||||
}
|
||||
|
||||
if ue.Coefficient != 0 {
|
||||
exercice.Coefficient = ue.Coefficient
|
||||
}
|
||||
|
||||
if len(ue.VideoURI) > 0 {
|
||||
exercice.VideoURI = ue.VideoURI
|
||||
}
|
||||
|
||||
if _, err := exercice.Update(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return exercice, nil
|
||||
}
|
||||
|
||||
func createExercice(theme fic.Theme, body []byte) (interface{}, error) {
|
||||
// Create a new exercice
|
||||
var ue fic.Exercice
|
||||
|
|
|
|||
Reference in a new issue