accept all datatypes in put
This commit is contained in:
14
handler.go
14
handler.go
@@ -5,6 +5,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"gitbase.de/gopackage/mgocrud"
|
||||
"github.com/gin-gonic/gin"
|
||||
mgo "gopkg.in/mgo.v2"
|
||||
@@ -355,9 +357,13 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||
field := newMStruct.Field(i)
|
||||
fieldT := newMStruct.Type().Field(i)
|
||||
|
||||
if (field.Kind() == reflect.Ptr || field.Kind() == reflect.Slice) &&
|
||||
!field.IsNil() {
|
||||
if fieldT.Anonymous && fieldT.Name == "Model" { // is embedded mgocrud.Model, so not in changes
|
||||
continue
|
||||
}
|
||||
|
||||
nilAble := (field.Kind() == reflect.Ptr || field.Kind() == reflect.Map || field.Kind() == reflect.Slice)
|
||||
|
||||
if (nilAble && !field.IsNil()) || !nilAble {
|
||||
// apply naming conventions of mgo for changeset
|
||||
tag := fieldT.Tag.Get("bson")
|
||||
if tag == "" && !strings.Contains(string(fieldT.Tag), ":") {
|
||||
@@ -378,7 +384,7 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||
orgMStruct.Field(i).Set(field)
|
||||
}
|
||||
}
|
||||
//spew.Dump(changes)
|
||||
spew.Dump(changes)
|
||||
//spew.Dump(orgM)
|
||||
|
||||
if err := validateObject(&Context{
|
||||
@@ -391,7 +397,7 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||
})
|
||||
return
|
||||
}
|
||||
//spew.Dump(orgM)
|
||||
|
||||
err = mgocrud.UpdateDocument(db, orgM, changes)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
|
||||
Reference in New Issue
Block a user