2020-05-27 13:48:09 +00: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 17:06:53 +00:00
|
|
|
package gitea
|
|
|
|
|
2020-05-27 13:48:09 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
type searchUsersResponse struct {
|
|
|
|
Users []*User `json:"data"`
|
|
|
|
}
|
|
|
|
|
2020-05-27 13:48:09 +00: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 17:06:53 +00:00
|
|
|
// SearchUsers finds users by query
|
2020-05-27 13:48:09 +00:00
|
|
|
func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, error) {
|
|
|
|
link, _ := url.Parse("/users/search")
|
|
|
|
link.RawQuery = opt.QueryEncode()
|
2019-04-25 17:06:53 +00:00
|
|
|
resp := new(searchUsersResponse)
|
2020-05-27 13:48:09 +00:00
|
|
|
err := c.getParsedResponse("GET", link.String(), nil, nil, &resp)
|
2019-04-25 17:06:53 +00:00
|
|
|
return resp.Users, err
|
|
|
|
}
|