Пример #1
0
func (env Env) UpdateKnot(c *gin.Context) {
	id := c.Param("id")
	if !bson.IsObjectIdHex(id) {
		sendBadRequest(c, fmt.Errorf("id_not_valid"))
	}
	mongoId := bson.ObjectIdHex(id)

	var new models.Knot
	var err error
	err = c.BindJSON(&new)

	if err != nil || !new.Validate() {
		sendBadRequest(c, fmt.Errorf("invalid_data"))
	} else {
		err = new.Update(env.db, mongoId)
		if err != nil {
			sendError(c, err)
		} else {
			c.JSON(http.StatusOK, gin.H{"status": true})
		}
	}
}