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
@@ -20,6 +20,7 @@ import (
|
||||
// listMembers list an organization's members
|
||||
func listMembers(ctx *context.APIContext, publicOnly bool) {
|
||||
var members []*models.User
|
||||
|
||||
members, _, err := models.FindOrgMembers(&models.FindOrgMembersOpts{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
PublicOnly: publicOnly,
|
||||
@@ -34,6 +35,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
||||
for i, member := range members {
|
||||
apiMembers[i] = convert.ToUser(member, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, apiMembers)
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user