Skip to content

Commit

Permalink
Add support for search by uid
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Sep 29, 2018
1 parent fc0001c commit 2c355e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ func GetUser(user *User) (bool, error) {
type SearchUserOptions struct {
Keyword string
Type UserType
UID int64
OrderBy SearchOrderBy
Page int
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
Expand All @@ -1355,9 +1356,14 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
if opts.SearchByEmail {
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
}

cond = cond.And(keywordCond)
}

if opts.UID > 0 {
cond = cond.And(builder.Eq{"id": opts.UID})
}

if !opts.IsActive.IsNone() {
cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
}
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func Search(ctx *context.APIContext) {
// in: query
// description: keyword
// type: string
// - name: uid
// in: query
// description: ID of the user to search for
// type: integer
// - name: limit
// in: query
// description: maximum number of users to return
Expand All @@ -45,6 +49,7 @@ func Search(ctx *context.APIContext) {
// "$ref": "#/definitions/User"
opts := &models.SearchUserOptions{
Keyword: strings.Trim(ctx.Query("q"), " "),
UID: com.StrTo(ctx.Query("uid")).MustInt64(),
Type: models.UserTypeIndividual,
PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
}
Expand Down
6 changes: 6 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5203,6 +5203,12 @@
"name": "q",
"in": "query"
},
{
"type": "integer",
"description": "ID of the user to search for",
"name": "uid",
"in": "query"
},
{
"type": "integer",
"description": "maximum number of users to return",
Expand Down

0 comments on commit 2c355e1

Please sign in to comment.