update users table with unique tag

This commit is contained in:
steven
2021-12-12 14:00:25 +08:00
parent 9db1f57307
commit b20741cca8
8 changed files with 103 additions and 20 deletions

View File

@ -37,6 +37,42 @@ func handleUpdateMyUserInfo(w http.ResponseWriter, r *http.Request) {
return
}
if *userPatch.Username != "" {
usernameUsable, _ := store.CheckUsernameUsable(*userPatch.Username)
if !usernameUsable {
json.NewEncoder(w).Encode(Response{
Succeed: false,
Message: "Username is existed",
Data: nil,
})
return
}
}
if *userPatch.GithubName != "" {
githubNameUsable, _ := store.CheckGithubNameUsable(*userPatch.GithubName)
if !githubNameUsable {
json.NewEncoder(w).Encode(Response{
Succeed: false,
Message: "GitHub name is existed",
Data: nil,
})
return
}
}
if *userPatch.WxOpenId != "" {
wxOpenIdUsable, _ := store.CheckWxOpenIdUsable(*userPatch.GithubName)
if !wxOpenIdUsable {
json.NewEncoder(w).Encode(Response{
Succeed: false,
Message: "Wx open id is existed",
Data: nil,
})
return
}
}
user, err := store.UpdateUser(userId, &userPatch)
if err != nil {