Skip to content

Commit

Permalink
feat: update user by id (#56)
Browse files Browse the repository at this point in the history
* feat: update user by id

* ID to id

* ID to id
  • Loading branch information
thaihuynhxyz authored Feb 10, 2023
1 parent 477edf8 commit aac6f65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion casdoorsdk/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ func DoPostBytesRaw(url string, contentType string, body io.Reader) ([]byte, err
// modifyUser is an encapsulation of user CUD(Create, Update, Delete) operations.
// possible actions are `add-user`, `update-user`, `delete-user`,
func modifyUser(action string, user *User, columns []string) (*Response, bool, error) {
return modifyUserById(action, user.GetId(), user, columns)
}

func modifyUserById(action string, id string, user *User, columns []string) (*Response, bool, error) {
queryMap := map[string]string{
"id": fmt.Sprintf("%s/%s", user.Owner, user.Name),
"id": id,
}

if len(columns) != 0 {
Expand Down
9 changes: 9 additions & 0 deletions casdoorsdk/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ func SetPassword(owner, name, oldPassword, newPassword string) (bool, error) {
return resp.Status == "ok", nil
}

func UpdateUserById(id string, user *User) (bool, error) {
_, affected, err := modifyUserById("update-user", id, user, nil)
return affected, err
}

func UpdateUser(user *User) (bool, error) {
_, affected, err := modifyUser("update-user", user, nil)
return affected, err
Expand All @@ -338,3 +343,7 @@ func CheckUserPassword(user *User) (bool, error) {
response, _, err := modifyUser("check-user-password", user, nil)
return response.Status == "ok", err
}

func (u User) GetId() string {
return fmt.Sprintf("%s/%s", u.Owner, u.Name)
}

0 comments on commit aac6f65

Please sign in to comment.