diff options
author | Ruzette Tanyag <ruzette@users.noreply.github.com> | 2017-02-08 05:00:16 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-02-08 02:00:16 -0800 |
commit | 0162d8ad08815b9b833fc651c7e185eab48cbbb2 (patch) | |
tree | 384c0032d766ad4a017a8a232590709134df8462 /model | |
parent | 5462f0119edb788428f90fc61c8651e4a8cd9ad1 (diff) | |
download | chat-0162d8ad08815b9b833fc651c7e185eab48cbbb2.tar.gz chat-0162d8ad08815b9b833fc651c7e185eab48cbbb2.tar.bz2 chat-0162d8ad08815b9b833fc651c7e185eab48cbbb2.zip |
Implement GET `/users/username/{username}` endpoint for APIv4 (#5310)
* added get user by username endpoint
* added get user by username unit test and driver
* changed username length to 22 characters max
* changed Params to UserName to Username
* reorganized get user by username and get user by email formatting in model/client4
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index e1b67673e..15f42dbc2 100644 --- a/model/client4.go +++ b/model/client4.go @@ -56,6 +56,10 @@ func (c *Client4) GetUserRoute(userId string) string { return fmt.Sprintf(c.GetUsersRoute()+"/%v", userId) } +func (c *Client4) GetUserByUsernameRoute(userName string) string { + return fmt.Sprintf(c.GetUsersRoute()+"/username/%v", userName) +} + func (c *Client4) GetUserByEmailRoute(email string) string { return fmt.Sprintf(c.GetUsersRoute()+"/email/%v", email) } @@ -226,6 +230,16 @@ func (c *Client4) GetUser(userId, etag string) (*User, *Response) { } } +// GetUserByUsername returns a user based on the provided user name string. +func (c *Client4) GetUserByUsername(userName, etag string) (*User, *Response) { + if r, err := c.DoApiGet(c.GetUserByUsernameRoute(userName), etag); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return UserFromJson(r.Body), BuildResponse(r) + } +} + // GetUserByEmail returns a user based on the provided user email string. func (c *Client4) GetUserByEmail(email, etag string) (*User, *Response) { if r, err := c.DoApiGet(c.GetUserByEmailRoute(email), etag); err != nil { |