mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-08-06 09:39:44 +08: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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user