diff --git a/controllers/user.go b/controllers/user.go index 81e46353..a9e45fc9 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -80,12 +80,16 @@ func (c *ApiController) GetUsers() { // @Title GetUser // @Tag User API // @Description get user -// @Param id query string true "The id of the user" +// @Param id query string true "The id of the user" +// @Param owner query string false "The owner of the user" +// @Param email query string false "The email of the user" +// @Param phone query string false "The phone of the user" // @Success 200 {object} object.User The Response object // @router /get-user [get] func (c *ApiController) GetUser() { id := c.Input().Get("id") email := c.Input().Get("email") + phone := c.Input().Get("phone") userId := c.Input().Get("userId") owner := c.Input().Get("owner") @@ -104,11 +108,14 @@ func (c *ApiController) GetUser() { } var user *object.User - if email != "" { + switch { + case email != "": user = object.GetUserByEmail(owner, email) - } else if userId != "" { + case phone != "": + user = object.GetUserByPhone(owner, phone) + case userId != "": user = object.GetUserByUserId(owner, userId) - } else { + default: user = object.GetUser(id) } diff --git a/object/user.go b/object/user.go index 9292a23d..00ce03ca 100644 --- a/object/user.go +++ b/object/user.go @@ -273,6 +273,24 @@ func GetUserByEmail(owner string, email string) *User { } } +func GetUserByPhone(owner string, phone string) *User { + if owner == "" || phone == "" { + return nil + } + + user := User{Owner: owner, Phone: phone} + existed, err := adapter.Engine.Get(&user) + if err != nil { + panic(err) + } + + if existed { + return &user + } else { + return nil + } +} + func GetUserByUserId(owner string, userId string) *User { if owner == "" || userId == "" { return nil