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/org/team.go | |
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/org/team.go')
-rw-r--r-- | routers/api/v1/org/team.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 9ca40a7796..0e92f2edb8 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -6,6 +6,7 @@ package org import ( + "fmt" "net/http" "strings" @@ -650,15 +651,17 @@ func SearchTeam(ctx *context.APIContext) { // items: // "$ref": "#/definitions/Team" + listOptions := utils.GetListOptions(ctx) + opts := &models.SearchTeamOptions{ UserID: ctx.User.ID, Keyword: strings.TrimSpace(ctx.Query("q")), OrgID: ctx.Org.Organization.ID, IncludeDesc: (ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc")), - ListOptions: utils.GetListOptions(ctx), + ListOptions: listOptions, } - teams, _, err := models.SearchTeam(opts) + teams, maxResults, err := models.SearchTeam(opts) if err != nil { log.Error("SearchTeam failed: %v", err) ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ @@ -681,6 +684,8 @@ func SearchTeam(ctx *context.APIContext) { apiTeams[i] = convert.ToTeam(teams[i]) } + 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": apiTeams, |