mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-19 10:12:54 +02:00
Migrate gitea-sdk to v0.12.0 (#133)
Migrate Update code.gitea.io/sdk/gitea to v0.12.0. Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/133 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
36
vendor/code.gitea.io/sdk/gitea/user_search.go
generated
vendored
36
vendor/code.gitea.io/sdk/gitea/user_search.go
generated
vendored
@ -1,14 +1,44 @@
|
||||
// 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.
|
||||
|
||||
package gitea
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type searchUsersResponse struct {
|
||||
Users []*User `json:"data"`
|
||||
}
|
||||
|
||||
// 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()
|
||||
}
|
||||
|
||||
// SearchUsers finds users by query
|
||||
func (c *Client) SearchUsers(query string, limit int) ([]*User, error) {
|
||||
func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, error) {
|
||||
link, _ := url.Parse("/users/search")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
resp := new(searchUsersResponse)
|
||||
err := c.getParsedResponse("GET", fmt.Sprintf("/users/search?q=%s&limit=%d", query, limit), nil, nil, &resp)
|
||||
err := c.getParsedResponse("GET", link.String(), nil, nil, &resp)
|
||||
return resp.Users, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user