diff options
author | Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> | 2020-06-21 10:22:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 16:22:06 +0800 |
commit | 81324cf37c87d834137a3b5ebf287adeed513f18 (patch) | |
tree | 918aa8464f8cbecd502105d98ec22d6062232533 /routers/api/v1/user | |
parent | a07cc0df76056ce2be1d8a89f38416cf511dd03b (diff) | |
download | gitea-81324cf37c87d834137a3b5ebf287adeed513f18.tar.gz gitea-81324cf37c87d834137a3b5ebf287adeed513f18.zip |
Add pagination headers on endpoints that support total count from database (#11145)
* begin work
* import fmt
* more work
* empty commit
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers/api/v1/user')
-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, |