Esempio n. 1
0
func (tr *TodoResource) UpdateTodo(c *gin.Context) {
	id, err := tr.getId(c)
	if err != nil {
		c.JSON(400, api.NewError("problem decoding id sent"))
		return
	}
	var todo api.Todo

	if c.Bind(&todo) != nil {
		c.JSON(400, api.NewError("problem decoding body"))
		return
	}
	todo.Id = int32(id)
	var existing api.Todo
	if tr.db.First(&existing, id).RecordNotFound() {
		c.JSON(404, api.NewError("not found"))
	} else {
		tr.db.Save(&todo)
		c.JSON(200, todo)
	}

}