extend add responsible from single to array
This commit is contained in:
@@ -16,14 +16,15 @@ func (a *APIHandler) AddNewResponsible(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var responsible models.Person
|
var responsibles []models.Person
|
||||||
err := c.BindJSON(&responsible)
|
err := c.BindJSON(&responsibles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.logger.Error("AddNewResponsible", err)
|
a.logger.Error("AddNewResponsible", err)
|
||||||
c.JSON(http.StatusInternalServerError, nil)
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, responsible := range responsibles {
|
||||||
err = a.DbHandler.AddNewResponsible(responsible)
|
err = a.DbHandler.AddNewResponsible(responsible)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
@@ -31,9 +32,10 @@ func (a *APIHandler) AddNewResponsible(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": "responsible added",
|
"message": "responsible(s) added",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user