proccessResults also for put/post
This commit is contained in:
parent
c2e158070f
commit
7f98182e94
78
handler.go
78
handler.go
@ -5,8 +5,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"gitbase.de/gopackage/mgocrud"
|
||||
"github.com/gin-gonic/gin"
|
||||
mgo "gopkg.in/mgo.v2"
|
||||
@ -55,21 +53,16 @@ func (api *API) collectionGetOneHandler(m mgocrud.ModelInterface) gin.HandlerFun
|
||||
return
|
||||
}
|
||||
|
||||
if i, ok := m.(interface {
|
||||
ProcessResults(*Context, interface{}) error
|
||||
}); ok {
|
||||
// custom select manipulation
|
||||
err := i.ProcessResults(&Context{
|
||||
API: api,
|
||||
Context: c,
|
||||
DB: db,
|
||||
}, newM)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
err = processResults(&Context{
|
||||
API: api,
|
||||
Context: c,
|
||||
DB: db,
|
||||
}, m, newM)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, newM)
|
||||
@ -200,21 +193,16 @@ func (api *API) collectionGetHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if i, ok := m.(interface {
|
||||
ProcessResults(*Context, interface{}) error
|
||||
}); ok {
|
||||
// custom select manipulation
|
||||
err := i.ProcessResults(&Context{
|
||||
API: api,
|
||||
Context: c,
|
||||
DB: db,
|
||||
}, results)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
err = processResults(&Context{
|
||||
API: api,
|
||||
Context: c,
|
||||
DB: db,
|
||||
}, m, results)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if setIdent {
|
||||
@ -287,6 +275,18 @@ func (api *API) collectionPostHandler(m mgocrud.ModelInterface) gin.HandlerFunc
|
||||
return
|
||||
}
|
||||
|
||||
err = processResults(&Context{
|
||||
API: api,
|
||||
Context: c,
|
||||
DB: db,
|
||||
}, m, readM)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, readM)
|
||||
}
|
||||
}
|
||||
@ -384,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{
|
||||
@ -427,6 +427,18 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
err = processResults(&Context{
|
||||
API: api,
|
||||
Context: c,
|
||||
DB: db,
|
||||
}, m, newM)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, newM)
|
||||
|
||||
}
|
||||
|
11
hooks.go
11
hooks.go
@ -83,3 +83,14 @@ func savedObject(c *Context, m mgocrud.ModelInterface, changes bson.M) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processResults(c *Context, m mgocrud.ModelInterface, results interface{}) error {
|
||||
if i, ok := m.(interface {
|
||||
ProcessResults(*Context, interface{}) error
|
||||
}); ok {
|
||||
// custom select manipulation
|
||||
err := i.ProcessResults(c, results)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user