From f9bc980b0b51844367305a347b6dbcb327c65677 Mon Sep 17 00:00:00 2001 From: oOOps Date: Wed, 13 Jun 2018 21:55:09 +0800 Subject: [PATCH] api: correct pagination in repository search api (#5293) --- pkg/context/api.go | 2 +- routes/api/v1/repo/repo.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/context/api.go b/pkg/context/api.go index 0aa025dcd..fab660241 100644 --- a/pkg/context/api.go +++ b/pkg/context/api.go @@ -43,7 +43,7 @@ func (c *APIContext) Error(status int, title string, obj interface{}) { }) } -// SetLinkHeader sets pagination link header by given totol number and page size. +// SetLinkHeader sets pagination link header by given total number and page size. func (c *APIContext) SetLinkHeader(total, pageSize int) { page := paginater.New(total, pageSize, c.QueryInt("page"), 0) links := make([]string, 0, 4) diff --git a/routes/api/v1/repo/repo.go b/routes/api/v1/repo/repo.go index db3b72516..6d4d0497a 100644 --- a/routes/api/v1/repo/repo.go +++ b/routes/api/v1/repo/repo.go @@ -25,6 +25,7 @@ func Search(c *context.APIContext) { Keyword: path.Base(c.Query("q")), OwnerID: c.QueryInt64("uid"), PageSize: convert.ToCorrectPageSize(c.QueryInt("limit")), + Page: c.QueryInt("page"), } // Check visibility. @@ -69,7 +70,7 @@ func Search(c *context.APIContext) { results[i] = repos[i].APIFormat(nil) } - c.SetLinkHeader(int(count), setting.API.MaxResponseItems) + c.SetLinkHeader(int(count), opts.PageSize) c.JSON(200, map[string]interface{}{ "ok": true, "data": results,