From c6f1825fe943b2aa6c98765be06ef1966841dc90 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 5 Aug 2019 12:08:57 +0800 Subject: [PATCH] add pagination for admin api get orgs and fix only list public orgs bug (#7742) (#7752) --- models/user.go | 4 +--- routers/api/v1/admin/org.go | 13 ++++++++++++- templates/swagger/v1_json.tmpl | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/models/user.go b/models/user.go index e48accf02d..cec783ff5f 100644 --- a/models/user.go +++ b/models/user.go @@ -1376,9 +1376,7 @@ type SearchUserOptions struct { } func (opts *SearchUserOptions) toConds() builder.Cond { - - var cond = builder.NewCond() - cond = cond.And(builder.Eq{"type": opts.Type}) + var cond builder.Cond = builder.Eq{"type": opts.Type} if len(opts.Keyword) > 0 { lowerKeyword := strings.ToLower(opts.Keyword) diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go index d740647cd4..c90e739626 100644 --- a/routers/api/v1/admin/org.go +++ b/routers/api/v1/admin/org.go @@ -82,6 +82,15 @@ func GetAllOrgs(ctx *context.APIContext) { // summary: List all organizations // produces: // - application/json + // parameters: + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results, maximum page size is 50 + // type: integer // responses: // "200": // "$ref": "#/responses/OrganizationList" @@ -90,7 +99,9 @@ func GetAllOrgs(ctx *context.APIContext) { users, _, err := models.SearchUsers(&models.SearchUserOptions{ Type: models.UserTypeOrganization, OrderBy: models.SearchOrderByAlphabetically, - PageSize: -1, + Page: ctx.QueryInt("page"), + PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), + Private: true, }) if err != nil { ctx.Error(500, "SearchOrganizations", err) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index d6d501ed22..51a2a720b3 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -33,6 +33,20 @@ ], "summary": "List all organizations", "operationId": "adminGetAllOrgs", + "parameters": [ + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, maximum page size is 50", + "name": "limit", + "in": "query" + } + ], "responses": { "200": { "$ref": "#/responses/OrganizationList"