diff --git a/routes/user/userValidators.go b/routes/user/userValidators.go index 02b26c3..730af41 100644 --- a/routes/user/userValidators.go +++ b/routes/user/userValidators.go @@ -56,7 +56,7 @@ func (r *updateUserRequest) updatedUser(role interface{}, // Only the Admin must be able to update user's role if role != "Admin" && r.Role != u.Role { return u, fmt.Errorf("Only Admin can update user's Role") - } else { + } else if role == "Admin" && r.Role != "" { u.Role = r.Role } @@ -64,7 +64,10 @@ func (r *updateUserRequest) updatedUser(role interface{}, if err := u.ByUsername(r.Username); err == nil { return u, fmt.Errorf("Username is alreaday taken") } - u.Username = r.Username + + if r.Username != "" { + u.Username = r.Username + } // If there is a new password then hash it and update it if r.Password != "" { @@ -74,8 +77,10 @@ func (r *updateUserRequest) updatedUser(role interface{}, } } - // Update male - u.Mail = r.Mail + // Update mail + if r.Mail != "" { + u.Mail = r.Mail + } return u, nil } diff --git a/routes/user/user_endpoints.go b/routes/user/user_endpoints.go index a1ace86..4c005b7 100644 --- a/routes/user/user_endpoints.go +++ b/routes/user/user_endpoints.go @@ -225,9 +225,7 @@ func addUser(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "id": newUser.ID, - }) + c.JSON(http.StatusOK, gin.H{"user": newUser.User}) } // UpdateUser godoc @@ -319,9 +317,7 @@ func updateUser(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "id": updatedUser.ID, - }) + c.JSON(http.StatusOK, gin.H{"user": updatedUser.User}) } // GetUser godoc @@ -393,7 +389,5 @@ func deleteUser(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "id": user.ID, - }) + c.JSON(http.StatusOK, gin.H{"user": user}) }