func UpdateUserHandler(c *gin.Context) { queryValues := c.Request.URL.Query() username := queryValues.Get("username") if username == "" { c.JSON(http.StatusBadRequest, gin.H{"missing": "username"}) return } var body models.User if err := c.BindJSON(&body); err != nil { return } if err := body.Validate(); err != nil { c.JSON(http.StatusBadRequest, err) return } if err := operations.UpdateUser(username, &body); err == nil { c.String(http.StatusOK, "Success") } else { c.JSON(http.StatusBadRequest, err) } }
func CreateUserHandler(c *gin.Context) { var body models.User if err := c.BindJSON(&body); err != nil { return } if err := body.Validate(); err != nil { c.JSON(http.StatusBadRequest, err) return } if err := operations.CreateUser(&body); err == nil { c.String(http.StatusOK, "Success") } else { c.JSON(http.StatusBadRequest, err) } }