2020-05-27 09:48:09 -04:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-04-25 13:06:53 -04:00
|
|
|
package gitea
|
|
|
|
|
2020-05-27 09:48:09 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
)
|
2019-04-25 13:06:53 -04:00
|
|
|
|
|
|
|
type searchUsersResponse struct {
|
|
|
|
Users []*User `json:"data"`
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:48:09 -04:00
|
|
|
// SearchUsersOption options for SearchUsers
|
|
|
|
type SearchUsersOption struct {
|
|
|
|
ListOptions
|
|
|
|
KeyWord string
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryEncode turns options into querystring argument
|
|
|
|
func (opt *SearchUsersOption) QueryEncode() string {
|
|
|
|
query := make(url.Values)
|
|
|
|
if opt.Page > 0 {
|
|
|
|
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
|
|
|
}
|
|
|
|
if opt.PageSize > 0 {
|
|
|
|
query.Add("limit", fmt.Sprintf("%d", opt.PageSize))
|
|
|
|
}
|
|
|
|
if len(opt.KeyWord) > 0 {
|
|
|
|
query.Add("q", opt.KeyWord)
|
|
|
|
}
|
|
|
|
return query.Encode()
|
|
|
|
}
|
|
|
|
|
2019-04-25 13:06:53 -04:00
|
|
|
// SearchUsers finds users by query
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, *Response, error) {
|
2020-05-27 09:48:09 -04:00
|
|
|
link, _ := url.Parse("/users/search")
|
|
|
|
link.RawQuery = opt.QueryEncode()
|
2020-09-15 22:01:41 -04:00
|
|
|
userResp := new(searchUsersResponse)
|
|
|
|
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &userResp)
|
|
|
|
return userResp.Users, resp, err
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|