diff --git a/admin/api/exercice.go b/admin/api/exercice.go index 50ffbfeb..442e4660 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "reflect" "strconv" "strings" "time" @@ -528,62 +529,36 @@ func updateExercice(c *gin.Context) { c.JSON(http.StatusOK, ue) } +type patchExercice struct { + Language *string `json:"lang,omitempty"` + Title *string `json:"title"` + Disabled *bool `json:"disabled"` + WIP *bool `json:"wip"` + URLId *string `json:"urlid"` + Statement *string `json:"statement"` + Overview *string `json:"overview"` + Headline *string `json:"headline"` + Finished *string `json:"finished"` + Issue *string `json:"issue"` + IssueKind *string `json:"issuekind"` + Gain *int64 `json:"gain"` + Coefficient *float64 `json:"coefficient"` +} + func partUpdateExercice(c *gin.Context) { exercice := c.MustGet("exercice").(*fic.Exercice) - var ue fic.Exercice + var ue patchExercice err := c.ShouldBindJSON(&ue) if err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()}) return } - 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.Headline) > 0 { - exercice.Headline = ue.Headline - } - - if len(ue.Finished) > 0 { - exercice.Finished = ue.Finished - } - - if len(ue.Overview) > 0 { - exercice.Overview = ue.Overview - } - - if len(ue.Issue) > 0 { - exercice.Issue = ue.Issue - } - - if len(ue.IssueKind) > 0 { - exercice.IssueKind = ue.IssueKind - } - - 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 + for _, field := range reflect.VisibleFields(reflect.TypeOf(ue)) { + if !reflect.ValueOf(ue).FieldByName(field.Name).IsNil() { + reflect.ValueOf(exercice).Elem().FieldByName(field.Name).Set(reflect.ValueOf(reflect.ValueOf(ue).FieldByName(field.Name).Elem().Interface())) + } } if _, err := exercice.Update(); err != nil { diff --git a/admin/static/views/exercice-list.html b/admin/static/views/exercice-list.html index 780c0b14..6046a9c5 100644 --- a/admin/static/views/exercice-list.html +++ b/admin/static/views/exercice-list.html @@ -74,9 +74,12 @@
Édition de masse -
+

+ Les propriétés en gras seront écrasées. +

+
- +