fixed readDocument in POST

This commit is contained in:
Sebastian Frank
2019-09-17 11:17:18 +02:00
parent 35bfaa7aa4
commit 90ef7bacca

View File

@@ -247,7 +247,8 @@ func (api *API) collectionPostHandler(m mgocrud.ModelInterface) gin.HandlerFunc
DB: db,
}, newM, nil); err != nil {
c.JSON(400, gin.H{
"error": err.Error(),
"error": err.Error(),
"apiContext": "validateObject",
})
return
}
@@ -255,15 +256,19 @@ func (api *API) collectionPostHandler(m mgocrud.ModelInterface) gin.HandlerFunc
err := mgocrud.CreateDocument(db, newM)
if err != nil {
c.JSON(500, gin.H{
"error": err.Error(),
"error": err.Error(),
"apiContext": "createDocument",
})
return
}
newM, err = getDocument(c, db, newM, nil)
readM := newModelOf(newM).(mgocrud.ModelInterface)
readM.SetID(newM.GetID())
err = mgocrud.ReadDocument(db, readM, nil)
if err != nil {
c.JSON(500, gin.H{
"error": err.Error(),
"error": err.Error(),
"apiContext": "readDocument",
})
return
}
@@ -272,14 +277,15 @@ func (api *API) collectionPostHandler(m mgocrud.ModelInterface) gin.HandlerFunc
API: api,
Context: c,
DB: db,
}, newM, nil); err != nil {
}, readM, nil); err != nil {
c.JSON(400, gin.H{
"error": err.Error(),
"error": err.Error(),
"apiContext": "savedObject",
})
return
}
c.JSON(200, newM)
c.JSON(200, readM)
}
}