mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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:
committed by
GitHub
parent
a07cc0df76
commit
81324cf37c
@@ -202,14 +202,16 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||
i++
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
|
||||
|
||||
// kept for backwards compatibility
|
||||
ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page))
|
||||
ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
|
||||
ctx.Header().Set("X-Total", strconv.FormatInt(commitsCountTotal, 10))
|
||||
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
|
||||
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount))
|
||||
|
||||
ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
|
||||
|
||||
ctx.JSON(http.StatusOK, &apiCommits)
|
||||
}
|
||||
|
||||
|
@@ -322,6 +322,8 @@ func ListIssues(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, listOptions.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", ctx.Repo.Repository.NumIssues))
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user