1
0
Fork 0
forked from forgejo/forgejo

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>
This commit is contained in:
Cirno the Strongest 2020-06-21 10:22:06 +02:00 committed by GitHub
parent a07cc0df76
commit 81324cf37c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 14 deletions

View file

@ -208,8 +208,10 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
}
repo := ctx.Repo.Repository
statuses, _, err := models.GetCommitStatuses(repo, sha, &models.CommitStatusOptions{
ListOptions: utils.GetListOptions(ctx),
listOptions := utils.GetListOptions(ctx)
statuses, maxResults, err := models.GetCommitStatuses(repo, sha, &models.CommitStatusOptions{
ListOptions: listOptions,
SortType: ctx.QueryTrim("sort"),
State: ctx.QueryTrim("state"),
})
@ -223,6 +225,9 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
apiStatuses = append(apiStatuses, status.APIFormat())
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.JSON(http.StatusOK, apiStatuses)
}