admin: Show what properties will be overwritted
This commit is contained in:
parent
eb85b28f5b
commit
3fcf705dcf
2 changed files with 27 additions and 49 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Reference in a new issue