summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/admin/user.go
diff options
context:
space:
mode:
authorCirno the Strongest <1447794+CirnoT@users.noreply.github.com>2020-06-21 10:22:06 +0200
committerGitHub <noreply@github.com>2020-06-21 16:22:06 +0800
commit81324cf37c87d834137a3b5ebf287adeed513f18 (patch)
tree918aa8464f8cbecd502105d98ec22d6062232533 /routers/api/v1/admin/user.go
parenta07cc0df76056ce2be1d8a89f38416cf511dd03b (diff)
downloadgitea-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/admin/user.go')
-rw-r--r--routers/api/v1/admin/user.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index f416ea9567..153ce66d76 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -351,10 +351,12 @@ func GetAllUsers(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- users, _, err := models.SearchUsers(&models.SearchUserOptions{
+ listOptions := utils.GetListOptions(ctx)
+
+ users, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
Type: models.UserTypeIndividual,
OrderBy: models.SearchOrderByAlphabetically,
- ListOptions: utils.GetListOptions(ctx),
+ ListOptions: listOptions,
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetAllUsers", err)
@@ -366,5 +368,7 @@ func GetAllUsers(ctx *context.APIContext) {
results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User.IsAdmin)
}
+ ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
+ ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.JSON(http.StatusOK, &results)
}