|
|
|
@ -11,6 +11,7 @@ type User struct {
|
|
|
|
|
Id string `json:"id"`
|
|
|
|
|
Username string `json:"username"`
|
|
|
|
|
Password string `json:"password"`
|
|
|
|
|
OpenId string `json:"openId"`
|
|
|
|
|
GithubName string `json:"githubName"`
|
|
|
|
|
CreatedAt string `json:"createdAt"`
|
|
|
|
|
UpdatedAt string `json:"updatedAt"`
|
|
|
|
@ -22,13 +23,14 @@ func CreateNewUser(username string, password string, githubName string) (User, e
|
|
|
|
|
Id: utils.GenUUID(),
|
|
|
|
|
Username: username,
|
|
|
|
|
Password: password,
|
|
|
|
|
OpenId: utils.GenUUID(),
|
|
|
|
|
GithubName: githubName,
|
|
|
|
|
CreatedAt: nowDateTimeStr,
|
|
|
|
|
UpdatedAt: nowDateTimeStr,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query := `INSERT INTO users (id, username, password, github_name, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)`
|
|
|
|
|
_, err := DB.Exec(query, newUser.Id, newUser.Username, newUser.Password, newUser.GithubName, newUser.CreatedAt, newUser.UpdatedAt)
|
|
|
|
|
query := `INSERT INTO users (id, username, password, open_id, github_name, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)`
|
|
|
|
|
_, err := DB.Exec(query, newUser.Id, newUser.Username, newUser.Password, newUser.OpenId, newUser.GithubName, newUser.CreatedAt, newUser.UpdatedAt)
|
|
|
|
|
|
|
|
|
|
return newUser, err
|
|
|
|
|
}
|
|
|
|
@ -64,24 +66,33 @@ func UpdateUser(id string, userPatch *UserPatch) (User, error) {
|
|
|
|
|
return user, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UpdateUserOpenId(userId string) (string, error) {
|
|
|
|
|
openId := utils.GenUUID()
|
|
|
|
|
|
|
|
|
|
query := `UPDATE users SET open_id=? WHERE id=?`
|
|
|
|
|
_, err := DB.Exec(query, openId, userId)
|
|
|
|
|
|
|
|
|
|
return openId, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserById(id string) (User, error) {
|
|
|
|
|
query := `SELECT id, username, password, github_name, created_at, updated_at FROM users WHERE id=?`
|
|
|
|
|
query := `SELECT id, username, password, open_id, github_name, created_at, updated_at FROM users WHERE id=?`
|
|
|
|
|
user := User{}
|
|
|
|
|
err := DB.QueryRow(query, id).Scan(&user.Id, &user.Username, &user.Password, &user.GithubName, &user.CreatedAt, &user.UpdatedAt)
|
|
|
|
|
err := DB.QueryRow(query, id).Scan(&user.Id, &user.Username, &user.Password, &user.OpenId, &user.GithubName, &user.CreatedAt, &user.UpdatedAt)
|
|
|
|
|
return user, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserByUsernameAndPassword(username string, password string) (User, error) {
|
|
|
|
|
query := `SELECT id, username, password, github_name, created_at, updated_at FROM users WHERE username=? AND password=?`
|
|
|
|
|
query := `SELECT id, username, password, open_id, github_name, created_at, updated_at FROM users WHERE username=? AND password=?`
|
|
|
|
|
user := User{}
|
|
|
|
|
err := DB.QueryRow(query, username, password).Scan(&user.Id, &user.Username, &user.Password, &user.GithubName, &user.CreatedAt, &user.UpdatedAt)
|
|
|
|
|
err := DB.QueryRow(query, username, password).Scan(&user.Id, &user.Username, &user.Password, &user.OpenId, &user.GithubName, &user.CreatedAt, &user.UpdatedAt)
|
|
|
|
|
return user, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserByGithubName(githubName string) (User, error) {
|
|
|
|
|
query := `SELECT id, username, password, github_name, created_at, updated_at FROM users WHERE github_name=?`
|
|
|
|
|
query := `SELECT id, username, password, open_id, github_name, created_at, updated_at FROM users WHERE github_name=?`
|
|
|
|
|
user := User{}
|
|
|
|
|
err := DB.QueryRow(query, githubName).Scan(&user.Id, &user.Username, &user.Password, &user.GithubName, &user.CreatedAt, &user.UpdatedAt)
|
|
|
|
|
err := DB.QueryRow(query, githubName).Scan(&user.Id, &user.Username, &user.Password, &user.OpenId, &user.GithubName, &user.CreatedAt, &user.UpdatedAt)
|
|
|
|
|
return user, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|