diff options
Diffstat (limited to 'routers/api/v1/user/user.go')
-rw-r--r-- | routers/api/v1/user/user.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index aaca53093e..426501f331 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -6,6 +6,7 @@ package user import ( + "fmt" "net/http" "strings" @@ -56,14 +57,16 @@ func Search(ctx *context.APIContext) { // items: // "$ref": "#/definitions/User" + listOptions := utils.GetListOptions(ctx) + opts := &models.SearchUserOptions{ Keyword: strings.Trim(ctx.Query("q"), " "), UID: com.StrTo(ctx.Query("uid")).MustInt64(), Type: models.UserTypeIndividual, - ListOptions: utils.GetListOptions(ctx), + ListOptions: listOptions, } - users, _, err := models.SearchUsers(opts) + users, maxResults, err := models.SearchUsers(opts) if err != nil { ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ "ok": false, @@ -77,6 +80,9 @@ func Search(ctx *context.APIContext) { results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin) } + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults)) + ctx.JSON(http.StatusOK, map[string]interface{}{ "ok": true, "data": results, |