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:
parent
a07cc0df76
commit
81324cf37c
9 changed files with 51 additions and 14 deletions
|
@ -6,6 +6,7 @@
|
|||
package org
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
@ -115,8 +116,10 @@ func GetAll(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
publicOrgs, _, err := models.SearchUsers(&models.SearchUserOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
publicOrgs, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
|
||||
ListOptions: listOptions,
|
||||
Type: models.UserTypeOrganization,
|
||||
OrderBy: models.SearchOrderByAlphabetically,
|
||||
Visible: vMode,
|
||||
|
@ -130,6 +133,8 @@ func GetAll(ctx *context.APIContext) {
|
|||
orgs[i] = convert.ToOrganization(publicOrgs[i])
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
|
||||
ctx.JSON(http.StatusOK, &orgs)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue