diff options
Diffstat (limited to 'routers')
57 files changed, 720 insertions, 216 deletions
diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go index 02068d6185..627f56eaec 100644 --- a/routers/admin/orgs.go +++ b/routers/admin/orgs.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -24,8 +25,10 @@ func Organizations(ctx *context.Context) { ctx.Data["PageIsAdminOrganizations"] = true routers.RenderUserSearch(ctx, &models.SearchUserOptions{ - Type: models.UserTypeOrganization, - PageSize: setting.UI.Admin.OrgPagingNum, - Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Type: models.UserTypeOrganization, + ListOptions: models.ListOptions{ + PageSize: setting.UI.Admin.OrgPagingNum, + }, + Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, }, tplOrgs) } diff --git a/routers/admin/users.go b/routers/admin/users.go index 71cda86cc2..6753699696 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -33,8 +34,10 @@ func Users(ctx *context.Context) { ctx.Data["PageIsAdminUsers"] = true routers.RenderUserSearch(ctx, &models.SearchUserOptions{ - Type: models.UserTypeIndividual, - PageSize: setting.UI.Admin.UserPagingNum, + Type: models.UserTypeIndividual, + ListOptions: models.ListOptions{ + PageSize: setting.UI.Admin.UserPagingNum, + }, SearchByEmail: true, }, tplUsers) } diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go index ca2ef574f3..01c2c49734 100644 --- a/routers/api/v1/admin/org.go +++ b/routers/api/v1/admin/org.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/user" + "code.gitea.io/gitea/routers/api/v1/utils" ) // CreateOrg api for create organization @@ -100,11 +101,10 @@ func GetAllOrgs(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" users, _, err := models.SearchUsers(&models.SearchUserOptions{ - Type: models.UserTypeOrganization, - OrderBy: models.SearchOrderByAlphabetically, - Page: ctx.QueryInt("page"), - PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), - Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate}, + Type: models.UserTypeOrganization, + OrderBy: models.SearchOrderByAlphabetically, + ListOptions: utils.GetListOptions(ctx), + Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate}, }) if err != nil { ctx.Error(http.StatusInternalServerError, "SearchOrganizations", err) diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index ebc651516a..28acc062cb 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/password" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/user" + "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/mailer" ) @@ -328,6 +329,15 @@ func GetAllUsers(ctx *context.APIContext) { // summary: List all users // 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/UserList" @@ -335,9 +345,9 @@ func GetAllUsers(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" users, _, err := models.SearchUsers(&models.SearchUserOptions{ - Type: models.UserTypeIndividual, - OrderBy: models.SearchOrderByAlphabetically, - PageSize: -1, + Type: models.UserTypeIndividual, + OrderBy: models.SearchOrderByAlphabetically, + ListOptions: utils.GetListOptions(ctx), }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetAllUsers", err) diff --git a/routers/api/v1/notify/repo.go b/routers/api/v1/notify/repo.go index b939d90f06..10c00c5467 100644 --- a/routers/api/v1/notify/repo.go +++ b/routers/api/v1/notify/repo.go @@ -51,6 +51,14 @@ func ListRepoNotifications(ctx *context.APIContext) { // type: string // format: date-time // required: false + // - 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/NotificationThreadList" @@ -61,6 +69,7 @@ func ListRepoNotifications(ctx *context.APIContext) { return } opts := models.FindNotificationOptions{ + ListOptions: utils.GetListOptions(ctx), UserID: ctx.User.ID, RepoID: ctx.Repo.Repository.ID, UpdatedBeforeUnix: before, diff --git a/routers/api/v1/notify/user.go b/routers/api/v1/notify/user.go index d16e4da0e0..7f731e25d4 100644 --- a/routers/api/v1/notify/user.go +++ b/routers/api/v1/notify/user.go @@ -41,6 +41,14 @@ func ListNotifications(ctx *context.APIContext) { // type: string // format: date-time // required: false + // - 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/NotificationThreadList" @@ -51,6 +59,7 @@ func ListNotifications(ctx *context.APIContext) { return } opts := models.FindNotificationOptions{ + ListOptions: utils.GetListOptions(ctx), UserID: ctx.User.ID, UpdatedBeforeUnix: before, UpdatedAfterUnix: since, diff --git a/routers/api/v1/org/hook.go b/routers/api/v1/org/hook.go index b3faac7b51..2fd084a13a 100644 --- a/routers/api/v1/org/hook.go +++ b/routers/api/v1/org/hook.go @@ -27,12 +27,20 @@ func ListHooks(ctx *context.APIContext) { // description: name of the organization // type: string // required: true + // - 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/HookList" org := ctx.Org.Organization - orgHooks, err := models.GetWebhooksByOrgID(org.ID) + orgHooks, err := models.GetWebhooksByOrgID(org.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetWebhooksByOrgID", err) return diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index 1575600a65..6450577f4c 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -14,14 +14,16 @@ import ( "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/user" + "code.gitea.io/gitea/routers/api/v1/utils" ) // 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, + members, _, err := models.FindOrgMembers(&models.FindOrgMembersOpts{ + OrgID: ctx.Org.Organization.ID, + PublicOnly: publicOnly, + ListOptions: utils.GetListOptions(ctx), }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUsersByIDs", err) @@ -48,6 +50,14 @@ func ListMembers(ctx *context.APIContext) { // description: name of the organization // type: string // required: true + // - 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/UserList" @@ -75,6 +85,14 @@ func ListPublicMembers(ctx *context.APIContext) { // description: name of the organization // type: string // required: true + // - 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 // produces: // - application/json // responses: diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 4bcd60a679..fde58bd5c1 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -13,10 +13,14 @@ import ( "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/user" + "code.gitea.io/gitea/routers/api/v1/utils" ) func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) { - if err := u.GetOrganizations(all); err != nil { + if err := u.GetOrganizations(&models.SearchOrganizationsOptions{ + ListOptions: utils.GetListOptions(ctx), + All: all, + }); err != nil { ctx.Error(http.StatusInternalServerError, "GetOrganizations", err) return } @@ -35,6 +39,15 @@ func ListMyOrgs(ctx *context.APIContext) { // summary: List the current user's 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" @@ -55,6 +68,14 @@ func ListUserOrgs(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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" @@ -95,11 +116,10 @@ func GetAll(ctx *context.APIContext) { } publicOrgs, _, err := models.SearchUsers(&models.SearchUserOptions{ - Type: models.UserTypeOrganization, - OrderBy: models.SearchOrderByAlphabetically, - Page: ctx.QueryInt("page"), - PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), - Visible: vMode, + ListOptions: utils.GetListOptions(ctx), + Type: models.UserTypeOrganization, + OrderBy: models.SearchOrderByAlphabetically, + Visible: vMode, }) if err != nil { ctx.Error(http.StatusInternalServerError, "SearchOrganizations", err) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 446287a343..1bf984b17f 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/user" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListTeams list all the teams of an organization @@ -30,12 +31,22 @@ func ListTeams(ctx *context.APIContext) { // description: name of the organization // type: string // required: true + // - 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/TeamList" org := ctx.Org.Organization - if err := org.GetTeams(); err != nil { + if err := org.GetTeams(&models.SearchTeamOptions{ + ListOptions: utils.GetListOptions(ctx), + }); err != nil { ctx.Error(http.StatusInternalServerError, "GetTeams", err) return } @@ -59,11 +70,20 @@ func ListUserTeams(ctx *context.APIContext) { // summary: List all the teams a user belongs to // 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/TeamList" - teams, err := models.GetUserTeams(ctx.User.ID) + teams, err := models.GetUserTeams(ctx.User.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserTeams", err) return @@ -284,6 +304,14 @@ func GetTeamMembers(ctx *context.APIContext) { // type: integer // format: int64 // required: true + // - 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/UserList" @@ -297,7 +325,9 @@ func GetTeamMembers(ctx *context.APIContext) { return } team := ctx.Org.Team - if err := team.GetMembers(); err != nil { + if err := team.GetMembers(&models.SearchMembersOptions{ + ListOptions: utils.GetListOptions(ctx), + }); err != nil { ctx.Error(http.StatusInternalServerError, "GetTeamMembers", err) return } @@ -436,12 +466,22 @@ func GetTeamRepos(ctx *context.APIContext) { // type: integer // format: int64 // required: true + // - 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/RepositoryList" team := ctx.Org.Team - if err := team.GetRepositories(); err != nil { + if err := team.GetRepositories(&models.SearchTeamOptions{ + ListOptions: utils.GetListOptions(ctx), + }); err != nil { ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err) } repos := make([]*api.Repository, len(team.Repos)) @@ -589,14 +629,14 @@ func SearchTeam(ctx *context.APIContext) { // in: query // description: include search within team description (defaults to true) // type: boolean - // - name: limit - // in: query - // description: limit size of results - // type: integer // - 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": // description: "SearchResults of a successful search" @@ -615,8 +655,7 @@ func SearchTeam(ctx *context.APIContext) { Keyword: strings.TrimSpace(ctx.Query("q")), OrgID: ctx.Org.Organization.ID, IncludeDesc: (ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc")), - PageSize: ctx.QueryInt("limit"), - Page: ctx.QueryInt("page"), + ListOptions: utils.GetListOptions(ctx), } teams, _, err := models.SearchTeam(opts) diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index aec389ab31..e99bc7b621 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListCollaborators list a repository's collaborators @@ -33,11 +34,19 @@ func ListCollaborators(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/UserList" - collaborators, err := ctx.Repo.Repository.GetCollaborators() + collaborators, err := ctx.Repo.Repository.GetCollaborators(utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "ListCollaborators", err) return diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index d8777eaf3a..f7da1698dc 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // GetSingleCommit get a commit via @@ -92,7 +93,11 @@ func GetAllCommits(ctx *context.APIContext) { // type: string // - name: page // in: query - // description: page number of requested commits + // 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": @@ -117,9 +122,13 @@ func GetAllCommits(ctx *context.APIContext) { } defer gitRepo.Close() - page := ctx.QueryInt("page") - if page <= 0 { - page = 1 + listOptions := utils.GetListOptions(ctx) + if listOptions.Page <= 0 { + listOptions.Page = 1 + } + + if listOptions.PageSize > git.CommitsRangeSize { + listOptions.PageSize = git.CommitsRangeSize } sha := ctx.Query("sha") @@ -154,10 +163,10 @@ func GetAllCommits(ctx *context.APIContext) { return } - pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(git.CommitsRangeSize))) + pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(listOptions.PageSize))) // Query commits - commits, err := baseCommit.CommitsByRange(page) + commits, err := baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize) if err != nil { ctx.ServerError("CommitsByRange", err) return @@ -181,13 +190,13 @@ func GetAllCommits(ctx *context.APIContext) { i++ } - ctx.SetLinkHeader(int(commitsCountTotal), git.CommitsRangeSize) + ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize) - ctx.Header().Set("X-Page", strconv.Itoa(page)) - ctx.Header().Set("X-PerPage", strconv.Itoa(git.CommitsRangeSize)) + 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(page < pageCount)) + ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount)) ctx.JSON(http.StatusOK, &apiCommits) } diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index 0bf7fc6cef..3536b7f43a 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -1,4 +1,5 @@ // Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -11,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" repo_service "code.gitea.io/gitea/services/repository" ) @@ -32,11 +34,19 @@ func ListForks(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/RepositoryList" - forks, err := ctx.Repo.Repository.GetForks() + forks, err := ctx.Repo.Repository.GetForks(utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetForks", err) return diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index 7fd7cd1be3..7fc5680c4f 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -34,11 +35,19 @@ func ListHooks(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/HookList" - hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) + hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetWebhooksByRepoID", err) return diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index c480f2a46f..c400ec6f3c 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -19,6 +19,7 @@ import ( api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/routers/api/v1/utils" issue_service "code.gitea.io/gitea/services/issue" ) @@ -38,10 +39,6 @@ func SearchIssues(ctx *context.APIContext) { // in: query // description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded // type: string - // - name: page - // in: query - // description: page number of requested issues - // type: integer // - name: q // in: query // description: search string @@ -55,6 +52,10 @@ func SearchIssues(ctx *context.APIContext) { // in: query // description: filter by type (issues / pulls) if set // type: string + // - name: page + // in: query + // description: page number of requested issues + // type: integer // responses: // "200": // "$ref": "#/responses/IssueList" @@ -72,7 +73,9 @@ func SearchIssues(ctx *context.APIContext) { // find repos user can access (for issue search) repoIDs := make([]int64, 0) opts := &models.SearchRepoOptions{ - PageSize: 15, + ListOptions: models.ListOptions{ + PageSize: 15, + }, Private: false, AllPublic: true, TopicOnly: false, @@ -146,9 +149,11 @@ func SearchIssues(ctx *context.APIContext) { // This would otherwise return all issues if no issues were found by the search. if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issues, err = models.Issues(&models.IssuesOptions{ + ListOptions: models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: setting.UI.IssuePagingNum, + }, RepoIDs: repoIDs, - Page: ctx.QueryInt("page"), - PageSize: setting.UI.IssuePagingNum, IsClosed: isClosed, IssueIDs: issueIDs, LabelIDs: labelIDs, @@ -198,10 +203,6 @@ func ListIssues(ctx *context.APIContext) { // in: query // description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded // type: string - // - name: page - // in: query - // description: page number of requested issues - // type: integer // - name: q // in: query // description: search string @@ -210,6 +211,14 @@ func ListIssues(ctx *context.APIContext) { // in: query // description: filter by type (issues / pulls) if set // type: string + // - 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/IssueList" @@ -245,6 +254,11 @@ func ListIssues(ctx *context.APIContext) { } } + listOptions := utils.GetListOptions(ctx) + if ctx.QueryInt("limit") == 0 { + listOptions.PageSize = setting.UI.IssuePagingNum + } + var isPull util.OptionalBool switch ctx.Query("type") { case "pulls": @@ -259,13 +273,12 @@ func ListIssues(ctx *context.APIContext) { // This would otherwise return all issues if no issues were found by the search. if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issues, err = models.Issues(&models.IssuesOptions{ - RepoIDs: []int64{ctx.Repo.Repository.ID}, - Page: ctx.QueryInt("page"), - PageSize: setting.UI.IssuePagingNum, - IsClosed: isClosed, - IssueIDs: issueIDs, - LabelIDs: labelIDs, - IsPull: isPull, + ListOptions: listOptions, + RepoIDs: []int64{ctx.Repo.Repository.ID}, + IsClosed: isClosed, + IssueIDs: issueIDs, + LabelIDs: labelIDs, + IsPull: isPull, }) } @@ -279,7 +292,7 @@ func ListIssues(ctx *context.APIContext) { apiIssues[i] = issues[i].APIFormat() } - ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum) + ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, listOptions.PageSize) ctx.JSON(http.StatusOK, &apiIssues) } diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 6b0e388194..6b7c2beac4 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -1,4 +1,5 @@ // Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -117,6 +118,14 @@ func ListRepoIssueComments(ctx *context.APIContext) { // description: if provided, only comments updated before the provided time are returned. // type: string // format: date-time + // - 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/CommentList" @@ -128,10 +137,11 @@ func ListRepoIssueComments(ctx *context.APIContext) { } comments, err := models.FindComments(models.FindCommentsOptions{ - RepoID: ctx.Repo.Repository.ID, - Since: since, - Before: before, - Type: models.CommentTypeComment, + ListOptions: utils.GetListOptions(ctx), + RepoID: ctx.Repo.Repository.ID, + Type: models.CommentTypeComment, + Since: since, + Before: before, }) if err != nil { ctx.Error(http.StatusInternalServerError, "FindComments", err) diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go index 9c1322b3fe..5e49ea4aae 100644 --- a/routers/api/v1/repo/issue_reaction.go +++ b/routers/api/v1/repo/issue_reaction.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // GetIssueCommentReactions list reactions of a comment from an issue @@ -245,6 +246,14 @@ func GetIssueReactions(ctx *context.APIContext) { // type: integer // format: int64 // required: true + // - 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/ReactionList" @@ -266,7 +275,7 @@ func GetIssueReactions(ctx *context.APIContext) { return } - reactions, err := models.FindIssueReactions(issue) + reactions, err := models.FindIssueReactions(issue, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err) return diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go index 3b7c20d4d3..01faa0d6b1 100644 --- a/routers/api/v1/repo/issue_stopwatch.go +++ b/routers/api/v1/repo/issue_stopwatch.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/routers/api/v1/utils" ) // StartIssueStopwatch creates a stopwatch for the given issue. @@ -197,6 +198,15 @@ func GetStopwatches(ctx *context.APIContext) { // swagger:operation GET /user/stopwatches user userGetStopWatches // --- // summary: Get list of all existing stopwatches + // 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 // consumes: // - application/json // produces: @@ -205,7 +215,7 @@ func GetStopwatches(ctx *context.APIContext) { // "200": // "$ref": "#/responses/StopWatchList" - sws, err := models.GetUserStopwatches(ctx.User.ID) + sws, err := models.GetUserStopwatches(ctx.User.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err) return diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go index 153b01de61..274da966fd 100644 --- a/routers/api/v1/repo/issue_subscription.go +++ b/routers/api/v1/repo/issue_subscription.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/routers/api/v1/utils" ) // AddIssueSubscription Subscribe user to issue @@ -158,6 +159,14 @@ func GetIssueSubscribers(ctx *context.APIContext) { // type: integer // format: int64 // required: true + // - 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/UserList" @@ -175,7 +184,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { return } - iwl, err := models.GetIssueWatchers(issue.ID) + iwl, err := models.GetIssueWatchers(issue.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err) return diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 323bf67d8e..9bad19a2e7 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -51,6 +51,14 @@ func ListTrackedTimes(ctx *context.APIContext) { // description: Only show times updated before the given time. This is a timestamp in RFC 3339 format // type: string // format: date-time + // - 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/TrackedTimeList" @@ -72,6 +80,7 @@ func ListTrackedTimes(ctx *context.APIContext) { } opts := models.FindTrackedTimesOptions{ + ListOptions: utils.GetListOptions(ctx), RepositoryID: ctx.Repo.Repository.ID, IssueID: issue.ID, } @@ -435,6 +444,14 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { // description: Only show times updated before the given time. This is a timestamp in RFC 3339 format // type: string // format: date-time + // - 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/TrackedTimeList" @@ -449,6 +466,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { } opts := models.FindTrackedTimesOptions{ + ListOptions: utils.GetListOptions(ctx), RepositoryID: ctx.Repo.Repository.ID, } @@ -495,6 +513,15 @@ func ListMyTrackedTimes(ctx *context.APIContext) { // swagger:operation GET /user/times user userCurrentTrackedTimes // --- // summary: List the current user's tracked times + // 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 // produces: // - application/json // parameters: @@ -512,7 +539,10 @@ func ListMyTrackedTimes(ctx *context.APIContext) { // "200": // "$ref": "#/responses/TrackedTimeList" - opts := models.FindTrackedTimesOptions{UserID: ctx.User.ID} + opts := models.FindTrackedTimesOptions{ + ListOptions: utils.GetListOptions(ctx), + UserID: ctx.User.ID, + } var err error if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = utils.GetQueryBeforeSince(ctx); err != nil { diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index 4ced8ec42f..4039100e1f 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -1,4 +1,5 @@ // Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -13,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // appendPrivateInformation appends the owner and key type information to api.PublicKey @@ -60,6 +62,14 @@ func ListDeployKeys(ctx *context.APIContext) { // in: query // description: fingerprint of the key // type: string + // - 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/DeployKeyList" @@ -72,7 +82,7 @@ func ListDeployKeys(ctx *context.APIContext) { if fingerprint != "" || keyID != 0 { keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint) } else { - keys, err = models.ListDeployKeys(ctx.Repo.Repository.ID) + keys, err = models.ListDeployKeys(ctx.Repo.Repository.ID, utils.GetListOptions(ctx)) } if err != nil { diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 16c905878d..6d438610be 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListLabels list all the labels of a repository @@ -32,11 +33,19 @@ func ListLabels(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/LabelList" - labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort")) + labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"), utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err) return diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index a979e2b69b..f3bb4386cb 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -1,4 +1,5 @@ // Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -12,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListMilestones list milestones for a repository @@ -36,11 +38,19 @@ func ListMilestones(ctx *context.APIContext) { // in: query // description: Milestone state, Recognised values are open, closed and all. Defaults to "open" // type: string + // - 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/MilestoneList" - milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state"))) + milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetMilestonesByRepoID", err) return diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index e2e6c2799b..1abc2806f8 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/notification" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/routers/api/v1/utils" issue_service "code.gitea.io/gitea/services/issue" pull_service "code.gitea.io/gitea/services/pull" ) @@ -41,10 +42,6 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions) // description: name of the repo // type: string // required: true - // - name: page - // in: query - // description: Page number - // type: integer // - name: state // in: query // description: "State of pull request: open or closed (optional)" @@ -68,12 +65,22 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions) // items: // type: integer // format: int64 + // - 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/PullRequestList" + listOptions := utils.GetListOptions(ctx) + prs, maxResults, err := models.PullRequests(ctx.Repo.Repository.ID, &models.PullRequestsOptions{ - Page: ctx.QueryInt("page"), + ListOptions: listOptions, State: ctx.QueryTrim("state"), SortType: ctx.QueryTrim("sort"), Labels: ctx.QueryStrings("labels"), @@ -106,7 +113,7 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions) apiPrs[i] = convert.ToAPIPullRequest(prs[i]) } - ctx.SetLinkHeader(int(maxResults), models.ItemsPerPage) + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) ctx.JSON(http.StatusOK, &apiPrs) } diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index f94d6ba635..5a04fbeec2 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -9,8 +9,8 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" releaseservice "code.gitea.io/gitea/services/release" ) @@ -59,20 +59,6 @@ func GetRelease(ctx *context.APIContext) { ctx.JSON(http.StatusOK, release.APIFormat()) } -func getPagesInfo(ctx *context.APIContext) (int, int) { - page := ctx.QueryInt("page") - if page == 0 { - page = 1 - } - perPage := ctx.QueryInt("per_page") - if perPage == 0 { - perPage = setting.API.DefaultPagingNum - } else if perPage > setting.API.MaxResponseItems { - perPage = setting.API.MaxResponseItems - } - return page, perPage -} - // ListReleases list a repository's releases func ListReleases(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/releases repository repoListReleases @@ -91,23 +77,32 @@ func ListReleases(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - name: per_page + // in: query + // description: items count every page wants to load + // type: integer + // deprecated: true // - name: page // in: query - // description: page wants to load + // description: page number of results to return (1-based) // type: integer - // - name: per_page + // - name: limit // in: query - // description: items count every page wants to load + // description: page size of results, maximum page size is 50 // type: integer // responses: // "200": // "$ref": "#/responses/ReleaseList" + listOptions := utils.GetListOptions(ctx) + if ctx.QueryInt("per_page") != 0 { + listOptions.PageSize = ctx.QueryInt("per_page") + } - page, limit := getPagesInfo(ctx) releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{ + ListOptions: listOptions, IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite, IncludeTags: false, - }, page, limit) + }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err) return diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index a13f6ebe0d..61c522bc05 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -16,7 +16,6 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" @@ -27,6 +26,7 @@ import ( api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/validation" + "code.gitea.io/gitea/routers/api/v1/utils" mirror_service "code.gitea.io/gitea/services/mirror" repo_service "code.gitea.io/gitea/services/repository" ) @@ -91,14 +91,6 @@ func Search(ctx *context.APIContext) { // in: query // description: include template repositories this user has access to (defaults to true) // type: boolean - // - 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 // - name: mode // in: query // description: type of repository to search for. Supported values are @@ -119,6 +111,14 @@ func Search(ctx *context.APIContext) { // description: sort order, either "asc" (ascending) or "desc" (descending). // Default is "asc", ignored if "sort" is not specified. // type: string + // - 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/SearchResults" @@ -126,12 +126,11 @@ func Search(ctx *context.APIContext) { // "$ref": "#/responses/validationError" opts := &models.SearchRepoOptions{ + ListOptions: utils.GetListOptions(ctx), Actor: ctx.User, Keyword: strings.Trim(ctx.Query("q"), " "), OwnerID: ctx.QueryInt64("uid"), PriorityOwnerID: ctx.QueryInt64("priority_owner_id"), - Page: ctx.QueryInt("page"), - PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), TopicOnly: ctx.QueryBool("topic"), Collaborate: util.OptionalBoolNone, Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")), @@ -214,7 +213,7 @@ func Search(ctx *context.APIContext) { results[i] = repo.APIFormat(accessMode) } - ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems) + ctx.SetLinkHeader(int(count), opts.PageSize) ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count)) ctx.JSON(http.StatusOK, api.SearchResults{ OK: true, diff --git a/routers/api/v1/repo/star.go b/routers/api/v1/repo/star.go index 65a99d442a..c68f8f2744 100644 --- a/routers/api/v1/repo/star.go +++ b/routers/api/v1/repo/star.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListStargazers list a repository's stargazers @@ -30,11 +31,19 @@ func ListStargazers(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/UserList" - stargazers, err := ctx.Repo.Repository.GetStargazers(-1) + stargazers, err := ctx.Repo.Repository.GetStargazers(utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetStargazers", err) return diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index b6b3d495ca..6ce71cc911 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/repofiles" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // NewCommitStatus creates a new CommitStatus @@ -89,11 +90,6 @@ func GetCommitStatuses(ctx *context.APIContext) { // description: sha of the commit // type: string // required: true - // - name: page - // in: query - // description: page number of results - // type: integer - // required: false // - name: sort // in: query // description: type of sort @@ -106,6 +102,14 @@ func GetCommitStatuses(ctx *context.APIContext) { // type: string // enum: [pending, success, error, failure, warning] // required: false + // - 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/StatusList" @@ -138,11 +142,6 @@ func GetCommitStatusesByRef(ctx *context.APIContext) { // description: name of branch/tag/commit // type: string // required: true - // - name: page - // in: query - // description: page number of results - // type: integer - // required: false // - name: sort // in: query // description: type of sort @@ -155,6 +154,14 @@ func GetCommitStatusesByRef(ctx *context.APIContext) { // type: string // enum: [pending, success, error, failure, warning] // required: false + // - 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/StatusList" @@ -202,9 +209,9 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { repo := ctx.Repo.Repository statuses, _, err := models.GetCommitStatuses(repo, sha, &models.CommitStatusOptions{ - Page: ctx.QueryInt("page"), - SortType: ctx.QueryTrim("sort"), - State: ctx.QueryTrim("state"), + ListOptions: utils.GetListOptions(ctx), + SortType: ctx.QueryTrim("sort"), + State: ctx.QueryTrim("state"), }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %v", repo.FullName(), sha, ctx.QueryInt("page"), err)) diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go index 352f842884..d3cd8ccc3b 100644 --- a/routers/api/v1/repo/subscriber.go +++ b/routers/api/v1/repo/subscriber.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListSubscribers list a repo's subscribers (i.e. watchers) @@ -30,11 +31,19 @@ func ListSubscribers(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/UserList" - subscribers, err := ctx.Repo.Repository.GetWatchers(0) + subscribers, err := ctx.Repo.Repository.GetWatchers(utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetWatchers", err) return diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go index 0c56f2a769..530b92a10d 100644 --- a/routers/api/v1/repo/topic.go +++ b/routers/api/v1/repo/topic.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListTopics returns list of current topics for repo @@ -33,12 +34,21 @@ func ListTopics(ctx *context.APIContext) { // description: name of the repo // type: string // required: true + // - 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/TopicNames" topics, err := models.FindTopics(&models.FindTopicOptions{ - RepoID: ctx.Repo.Repository.ID, + ListOptions: utils.GetListOptions(ctx), + RepoID: ctx.Repo.Repository.ID, }) if err != nil { log.Error("ListTopics failed: %v", err) @@ -231,7 +241,7 @@ func DeleteTopic(ctx *context.APIContext) { } // TopicSearch search for creating topic -func TopicSearch(ctx *context.Context) { +func TopicSearch(ctx *context.APIContext) { // swagger:operation GET /topics/search repository topicSearch // --- // summary: search topics via keyword @@ -243,6 +253,14 @@ func TopicSearch(ctx *context.Context) { // description: keywords to search // required: true // type: string + // - 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/TopicListResponse" @@ -256,9 +274,17 @@ func TopicSearch(ctx *context.Context) { kw := ctx.Query("q") + listOptions := utils.GetListOptions(ctx) + if listOptions.Page < 1 { + listOptions.Page = 1 + } + if listOptions.PageSize < 1 { + listOptions.PageSize = 10 + } + topics, err := models.FindTopics(&models.FindTopicOptions{ - Keyword: kw, - Limit: 10, + Keyword: kw, + ListOptions: listOptions, }) if err != nil { log.Error("SearchTopics failed: %v", err) diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index ec52f02d38..a65bdc51c1 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // ListAccessTokens list all the access tokens @@ -26,11 +27,19 @@ func ListAccessTokens(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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/AccessTokenList" - tokens, err := models.ListAccessTokens(ctx.User.ID) + tokens, err := models.ListAccessTokens(ctx.User.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "ListAccessTokens", err) return diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go index bd68070265..6e180b37f1 100644 --- a/routers/api/v1/user/follower.go +++ b/routers/api/v1/user/follower.go @@ -1,4 +1,5 @@ // Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -11,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) func responseAPIUsers(ctx *context.APIContext, users []*models.User) { @@ -22,7 +24,7 @@ func responseAPIUsers(ctx *context.APIContext, users []*models.User) { } func listUserFollowers(ctx *context.APIContext, u *models.User) { - users, err := u.GetFollowers(ctx.QueryInt("page")) + users, err := u.GetFollowers(utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err) return @@ -35,6 +37,15 @@ func ListMyFollowers(ctx *context.APIContext) { // swagger:operation GET /user/followers user userCurrentListFollowers // --- // summary: List the authenticated user's followers + // 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 // produces: // - application/json // responses: @@ -57,6 +68,14 @@ func ListFollowers(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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/UserList" @@ -69,7 +88,7 @@ func ListFollowers(ctx *context.APIContext) { } func listUserFollowing(ctx *context.APIContext, u *models.User) { - users, err := u.GetFollowing(ctx.QueryInt("page")) + users, err := u.GetFollowing(utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetFollowing", err) return @@ -82,6 +101,15 @@ func ListMyFollowing(ctx *context.APIContext) { // swagger:operation GET /user/following user userCurrentListFollowing // --- // summary: List the users that the authenticated user is following + // 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 // produces: // - application/json // responses: @@ -104,6 +132,14 @@ func ListFollowing(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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/UserList" diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index b6133ca7be..a4f6d0e924 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -11,10 +11,11 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) -func listGPGKeys(ctx *context.APIContext, uid int64) { - keys, err := models.ListGPGKeys(uid) +func listGPGKeys(ctx *context.APIContext, uid int64, listOptions models.ListOptions) { + keys, err := models.ListGPGKeys(uid, listOptions) if err != nil { ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err) return @@ -41,6 +42,14 @@ func ListGPGKeys(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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/GPGKeyList" @@ -49,7 +58,7 @@ func ListGPGKeys(ctx *context.APIContext) { if ctx.Written() { return } - listGPGKeys(ctx, user.ID) + listGPGKeys(ctx, user.ID, utils.GetListOptions(ctx)) } //ListMyGPGKeys get the GPG key list of the authenticated user @@ -57,13 +66,22 @@ func ListMyGPGKeys(ctx *context.APIContext) { // swagger:operation GET /user/gpg_keys user userCurrentListGPGKeys // --- // summary: List the authenticated user's GPG keys + // 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 // produces: // - application/json // responses: // "200": // "$ref": "#/responses/GPGKeyList" - listGPGKeys(ctx, ctx.User.ID) + listGPGKeys(ctx, ctx.User.ID, utils.GetListOptions(ctx)) } //GetGPGKey get the GPG key based on a id diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index 7cf6fa383d..58705dd2f1 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/repo" + "code.gitea.io/gitea/routers/api/v1/utils" ) // appendPrivateInformation appends the owner and key type information to api.PublicKey @@ -79,7 +80,7 @@ func listPublicKeys(ctx *context.APIContext, user *models.User) { } } else { // Use ListPublicKeys - keys, err = models.ListPublicKeys(user.ID) + keys, err = models.ListPublicKeys(user.ID, utils.GetListOptions(ctx)) } if err != nil { @@ -109,6 +110,14 @@ func ListMyPublicKeys(ctx *context.APIContext) { // in: query // description: fingerprint of the key // type: string + // - 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 // produces: // - application/json // responses: @@ -135,6 +144,14 @@ func ListPublicKeys(ctx *context.APIContext) { // in: query // description: fingerprint of the key // type: string + // - 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/PublicKeyList" diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 90518f95e5..4024bf96cf 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -10,11 +10,16 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // listUserRepos - List the repositories owned by the given user. func listUserRepos(ctx *context.APIContext, u *models.User, private bool) { - repos, err := models.GetUserRepositories(u.ID, private, 1, u.NumRepos, "") + repos, err := models.GetUserRepositories(&models.SearchRepoOptions{ + Actor: u, + Private: private, + ListOptions: utils.GetListOptions(ctx), + }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err) return @@ -47,6 +52,14 @@ func ListUserRepos(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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/RepositoryList" @@ -66,11 +79,24 @@ func ListMyRepos(ctx *context.APIContext) { // summary: List the repos that the authenticated user owns or has access to // 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/RepositoryList" - ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos, "") + ownRepos, err := models.GetUserRepositories(&models.SearchRepoOptions{ + Actor: ctx.User, + Private: true, + ListOptions: utils.GetListOptions(ctx), + }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err) return @@ -106,6 +132,14 @@ func ListOrgRepos(ctx *context.APIContext) { // description: name of the organization // type: string // required: true + // - 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/RepositoryList" diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index e5d3a8f0a0..0e0875f04e 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -1,4 +1,5 @@ // Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -10,12 +11,13 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // getStarredRepos returns the repos that the user with the specified userID has // starred -func getStarredRepos(user *models.User, private bool) ([]*api.Repository, error) { - starredRepos, err := models.GetStarredRepos(user.ID, private) +func getStarredRepos(user *models.User, private bool, listOptions models.ListOptions) ([]*api.Repository, error) { + starredRepos, err := models.GetStarredRepos(user.ID, private, listOptions) if err != nil { return nil, err } @@ -44,13 +46,21 @@ func GetStarredRepos(ctx *context.APIContext) { // description: username of user // type: string // required: true + // - 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/RepositoryList" user := GetUserByParams(ctx) private := user.ID == ctx.User.ID - repos, err := getStarredRepos(user, private) + repos, err := getStarredRepos(user, private, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "getStarredRepos", err) } @@ -62,13 +72,22 @@ func GetMyStarredRepos(ctx *context.APIContext) { // swagger:operation GET /user/starred user userCurrentListStarred // --- // summary: The repos that the authenticated user has starred + // 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 // produces: // - application/json // responses: // "200": // "$ref": "#/responses/RepositoryList" - repos, err := getStarredRepos(ctx.User, true) + repos, err := getStarredRepos(ctx.User, true, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "getStarredRepos", err) } diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 3f17a6f91b..c0b0f1170c 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -12,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" "github.com/unknwon/com" ) @@ -33,9 +35,13 @@ func Search(ctx *context.APIContext) { // description: ID of the user to search for // type: integer // format: int64 + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer // - name: limit // in: query - // description: maximum number of users to return + // description: page size of results, maximum page size is 50 // type: integer // responses: // "200": @@ -51,10 +57,10 @@ func Search(ctx *context.APIContext) { // "$ref": "#/definitions/User" opts := &models.SearchUserOptions{ - Keyword: strings.Trim(ctx.Query("q"), " "), - UID: com.StrTo(ctx.Query("uid")).MustInt64(), - Type: models.UserTypeIndividual, - PageSize: com.StrTo(ctx.Query("limit")).MustInt(), + Keyword: strings.Trim(ctx.Query("q"), " "), + UID: com.StrTo(ctx.Query("uid")).MustInt64(), + Type: models.UserTypeIndividual, + ListOptions: utils.GetListOptions(ctx), } users, _, err := models.SearchUsers(opts) diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index ec8543dcf0..e54709b599 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -11,12 +11,13 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" ) // getWatchedRepos returns the repos that the user with the specified userID is // watching -func getWatchedRepos(user *models.User, private bool) ([]*api.Repository, error) { - watchedRepos, err := models.GetWatchedRepos(user.ID, private) +func getWatchedRepos(user *models.User, private bool, listOptions models.ListOptions) ([]*api.Repository, error) { + watchedRepos, err := models.GetWatchedRepos(user.ID, private, listOptions) if err != nil { return nil, err } @@ -45,13 +46,21 @@ func GetWatchedRepos(ctx *context.APIContext) { // in: path // description: username of the user // required: true + // - 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/RepositoryList" user := GetUserByParams(ctx) private := user.ID == ctx.User.ID - repos, err := getWatchedRepos(user, private) + repos, err := getWatchedRepos(user, private, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err) } @@ -65,11 +74,20 @@ func GetMyWatchedRepos(ctx *context.APIContext) { // summary: List repositories watched by the authenticated user // 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/RepositoryList" - repos, err := getWatchedRepos(ctx.User, true) + repos, err := getWatchedRepos(ctx.User, true, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err) } diff --git a/routers/api/v1/utils/utils.go b/routers/api/v1/utils/utils.go index 35f4873964..e02406d137 100644 --- a/routers/api/v1/utils/utils.go +++ b/routers/api/v1/utils/utils.go @@ -8,7 +8,9 @@ import ( "strings" "time" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/convert" ) // UserID user ID of authenticated user, or 0 if not authenticated @@ -44,3 +46,11 @@ func GetQueryBeforeSince(ctx *context.APIContext) (before, since int64, err erro } return before, since, nil } + +// GetListOptions returns list options using the page and limit parameters +func GetListOptions(ctx *context.APIContext) models.ListOptions { + return models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), + } +} diff --git a/routers/home.go b/routers/home.go index 96e13cc68f..77a7e153e2 100644 --- a/routers/home.go +++ b/routers/home.go @@ -137,9 +137,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { ctx.Data["TopicOnly"] = topicOnly repos, count, err = models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: models.ListOptions{ + Page: page, + PageSize: opts.PageSize, + }, Actor: ctx.User, - Page: page, - PageSize: opts.PageSize, OrderBy: orderBy, Private: opts.Private, Keyword: keyword, @@ -250,10 +252,10 @@ func ExploreUsers(ctx *context.Context) { ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled RenderUserSearch(ctx, &models.SearchUserOptions{ - Type: models.UserTypeIndividual, - PageSize: setting.UI.ExplorePagingNum, - IsActive: util.OptionalBoolTrue, - Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Type: models.UserTypeIndividual, + ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum}, + IsActive: util.OptionalBoolTrue, + Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, }, tplExploreUsers) } @@ -270,9 +272,9 @@ func ExploreOrganizations(ctx *context.Context) { } RenderUserSearch(ctx, &models.SearchUserOptions{ - Type: models.UserTypeOrganization, - PageSize: setting.UI.ExplorePagingNum, - Visible: visibleTypes, + Type: models.UserTypeOrganization, + ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum}, + Visible: visibleTypes, }, tplExploreOrganizations) } diff --git a/routers/org/home.go b/routers/org/home.go index 2f461d861b..e1bea5b7a6 100644 --- a/routers/org/home.go +++ b/routers/org/home.go @@ -76,14 +76,16 @@ func Home(ctx *context.Context) { err error ) repos, count, err = models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: models.ListOptions{ + PageSize: setting.UI.User.RepoPagingNum, + Page: page, + }, Keyword: keyword, OwnerID: org.ID, OrderBy: orderBy, Private: ctx.IsSigned, Actor: ctx.User, - Page: page, IsProfile: true, - PageSize: setting.UI.User.RepoPagingNum, IncludeDescription: setting.UI.SearchRepoDescription, }) if err != nil { @@ -92,9 +94,9 @@ func Home(ctx *context.Context) { } var opts = models.FindOrgMembersOpts{ - OrgID: org.ID, - PublicOnly: true, - Limit: 25, + OrgID: org.ID, + PublicOnly: true, + ListOptions: models.ListOptions{Page: 1, PageSize: 25}, } if ctx.User != nil { @@ -106,7 +108,7 @@ func Home(ctx *context.Context) { opts.PublicOnly = !isMember && !ctx.User.IsAdmin } - members, _, err := models.FindOrgMembers(opts) + members, _, err := models.FindOrgMembers(&opts) if err != nil { ctx.ServerError("FindOrgMembers", err) return diff --git a/routers/org/members.go b/routers/org/members.go index 6bccb3d972..053bd21f5e 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -51,9 +52,9 @@ func Members(ctx *context.Context) { } pager := context.NewPagination(int(total), setting.UI.MembersPagingNum, page, 5) - opts.Start = (page - 1) * setting.UI.MembersPagingNum - opts.Limit = setting.UI.MembersPagingNum - members, membersIsPublic, err := models.FindOrgMembers(opts) + opts.ListOptions.Page = (page - 1) * setting.UI.MembersPagingNum + opts.ListOptions.PageSize = setting.UI.MembersPagingNum + members, membersIsPublic, err := models.FindOrgMembers(&opts) if err != nil { ctx.ServerError("GetMembers", err) return diff --git a/routers/org/setting.go b/routers/org/setting.go index 0aeefb50af..df5ff24c0e 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -155,7 +155,7 @@ func Webhooks(ctx *context.Context) { ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks" ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") - ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID) + ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID, models.ListOptions{}) if err != nil { ctx.ServerError("GetWebhooksByOrgId", err) return diff --git a/routers/org/teams.go b/routers/org/teams.go index 2aa69f5e93..03fbf068da 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -38,7 +38,7 @@ func Teams(ctx *context.Context) { ctx.Data["PageIsOrgTeams"] = true for _, t := range org.Teams { - if err := t.GetMembers(); err != nil { + if err := t.GetMembers(&models.SearchMembersOptions{}); err != nil { ctx.ServerError("GetMembers", err) return } @@ -246,7 +246,7 @@ func TeamMembers(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamMembers"] = true - if err := ctx.Org.Team.GetMembers(); err != nil { + if err := ctx.Org.Team.GetMembers(&models.SearchMembersOptions{}); err != nil { ctx.ServerError("GetMembers", err) return } @@ -258,7 +258,7 @@ func TeamRepositories(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamRepos"] = true - if err := ctx.Org.Team.GetRepositories(); err != nil { + if err := ctx.Org.Team.GetRepositories(&models.SearchTeamOptions{}); err != nil { ctx.ServerError("GetRepositories", err) return } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index e581d39526..cb9727fccc 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -58,8 +58,13 @@ func Commits(ctx *context.Context) { page = 1 } + pageSize := ctx.QueryInt("limit") + if pageSize <= 0 { + pageSize = git.CommitsRangeSize + } + // Both `git log branchName` and `git log commitId` work. - commits, err := ctx.Repo.Commit.CommitsByRange(page) + commits, err := ctx.Repo.Commit.CommitsByRange(page, pageSize) if err != nil { ctx.ServerError("CommitsByRange", err) return diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 49481e7e2e..fdade2795d 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -195,13 +195,15 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB issues = []*models.Issue{} } else { issues, err = models.Issues(&models.IssuesOptions{ + ListOptions: models.ListOptions{ + Page: pager.Paginater.Current(), + PageSize: setting.UI.IssuePagingNum, + }, RepoIDs: []int64{repo.ID}, AssigneeID: assigneeID, PosterID: posterID, MentionedID: mentionedID, MilestoneID: milestoneID, - Page: pager.Paginater.Current(), - PageSize: setting.UI.IssuePagingNum, IsClosed: util.OptionalBoolOf(isShowClosed), IsPull: isPullOption, LabelIDs: labelIDs, @@ -246,7 +248,7 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB return } - labels, err := models.GetLabelsByRepoID(repo.ID, "") + labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{}) if err != nil { ctx.ServerError("GetLabelsByRepoID", err) return @@ -309,7 +311,7 @@ func Issues(ctx *context.Context) { var err error // Get milestones. - ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state"))) + ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), models.ListOptions{}) if err != nil { ctx.ServerError("GetAllRepoMilestones", err) return @@ -347,7 +349,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo return nil } - labels, err := models.GetLabelsByRepoID(repo.ID, "") + labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{}) if err != nil { ctx.ServerError("GetLabelsByRepoID", err) return nil @@ -733,7 +735,7 @@ func ViewIssue(ctx *context.Context) { for i := range issue.Labels { labelIDMark[issue.Labels[i].ID] = true } - labels, err := models.GetLabelsByRepoID(repo.ID, "") + labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{}) if err != nil { ctx.ServerError("GetLabelsByRepoID", err) return diff --git a/routers/repo/issue_label.go b/routers/repo/issue_label.go index 98f2dded31..e61fcbe5cb 100644 --- a/routers/repo/issue_label.go +++ b/routers/repo/issue_label.go @@ -50,7 +50,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) { // RetrieveLabels find all the labels of a repository func RetrieveLabels(ctx *context.Context) { - labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort")) + labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"), models.ListOptions{}) if err != nil { ctx.ServerError("RetrieveLabels.GetLabels", err) return diff --git a/routers/repo/release.go b/routers/repo/release.go index 0ab8450bd5..5454195181 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" @@ -56,24 +57,26 @@ func Releases(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.releases") ctx.Data["PageIsReleaseList"] = true - page := ctx.QueryInt("page") - if page <= 1 { - page = 1 - } - limit := ctx.QueryInt("limit") - if limit <= 0 { - limit = 10 - } - writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases) ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived opts := models.FindReleasesOptions{ + ListOptions: models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), + }, IncludeDrafts: writeAccess, IncludeTags: true, } - releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts, page, limit) + if opts.ListOptions.Page <= 1 { + opts.ListOptions.Page = 1 + } + if opts.ListOptions.PageSize <= 0 { + opts.ListOptions.Page = 10 + } + + releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts) if err != nil { ctx.ServerError("GetReleasesByRepoID", err) return @@ -121,7 +124,7 @@ func Releases(ctx *context.Context) { ctx.Data["Releases"] = releases - pager := context.NewPagination(int(count), limit, page, 5) + pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) ctx.Data["Page"] = pager diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 6ad0b4a967..22699f9e8d 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -486,7 +486,7 @@ func Collaboration(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsCollaboration"] = true - users, err := ctx.Repo.Repository.GetCollaborators() + users, err := ctx.Repo.Repository.GetCollaborators(models.ListOptions{}) if err != nil { ctx.ServerError("GetCollaborators", err) return @@ -738,7 +738,7 @@ func DeployKeys(ctx *context.Context) { ctx.Data["PageIsSettingsKeys"] = true ctx.Data["DisableSSH"] = setting.SSH.Disabled - keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) + keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID, models.ListOptions{}) if err != nil { ctx.ServerError("ListDeployKeys", err) return @@ -753,7 +753,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) { ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys") ctx.Data["PageIsSettingsKeys"] = true - keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) + keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID, models.ListOptions{}) if err != nil { ctx.ServerError("ListDeployKeys", err) return diff --git a/routers/repo/view.go b/routers/repo/view.go index 8730523d89..3fbff007e1 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -522,7 +522,7 @@ func renderCode(ctx *context.Context) { } // RenderUserCards render a page show users according the input templaet -func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) { +func RenderUserCards(ctx *context.Context, total int, getter func(opts models.ListOptions) ([]*models.User, error), tpl base.TplName) { page := ctx.QueryInt("page") if page <= 0 { page = 1 @@ -530,7 +530,7 @@ func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]* pager := context.NewPagination(total, models.ItemsPerPage, page, 5) ctx.Data["Page"] = pager - items, err := getter(pager.Paginater.Current()) + items, err := getter(models.ListOptions{Page: pager.Paginater.Current()}) if err != nil { ctx.ServerError("getter", err) return @@ -561,7 +561,7 @@ func Stars(ctx *context.Context) { func Forks(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repos.forks") - forks, err := ctx.Repo.Repository.GetForks() + forks, err := ctx.Repo.Repository.GetForks(models.ListOptions{}) if err != nil { ctx.ServerError("GetForks", err) return diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index 9ae15882c1..049ce0aedf 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -38,7 +38,7 @@ func Webhooks(ctx *context.Context) { ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks" ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/") - ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) + ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, models.ListOptions{}) if err != nil { ctx.ServerError("GetWebhooksByRepoID", err) return diff --git a/routers/user/home.go b/routers/user/home.go index 0d78b17dad..8b3155ea0b 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -53,7 +53,7 @@ func getDashboardContextUser(ctx *context.Context) *models.User { } ctx.Data["ContextUser"] = ctxUser - if err := ctx.User.GetOrganizations(true); err != nil { + if err := ctx.User.GetOrganizations(&models.SearchOrganizationsOptions{All: true}); err != nil { ctx.ServerError("GetOrganizations", err) return nil } @@ -609,7 +609,7 @@ func Issues(ctx *context.Context) { // ShowSSHKeys output all the ssh keys of user by uid func ShowSSHKeys(ctx *context.Context, uid int64) { - keys, err := models.ListPublicKeys(uid) + keys, err := models.ListPublicKeys(uid, models.ListOptions{}) if err != nil { ctx.ServerError("ListPublicKeys", err) return @@ -625,7 +625,7 @@ func ShowSSHKeys(ctx *context.Context, uid int64) { // ShowGPGKeys output all the public GPG keys of user by uid func ShowGPGKeys(ctx *context.Context, uid int64) { - keys, err := models.ListGPGKeys(uid) + keys, err := models.ListGPGKeys(uid, models.ListOptions{}) if err != nil { ctx.ServerError("ListGPGKeys", err) return diff --git a/routers/user/profile.go b/routers/user/profile.go index b5933788dd..808ce382c7 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -172,12 +172,14 @@ func Profile(ctx *context.Context) { case "stars": ctx.Data["PageIsProfileStarList"] = true repos, count, err = models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: models.ListOptions{ + PageSize: setting.UI.User.RepoPagingNum, + Page: page, + }, Actor: ctx.User, Keyword: keyword, OrderBy: orderBy, Private: ctx.IsSigned, - Page: page, - PageSize: setting.UI.User.RepoPagingNum, StarredByID: ctxUser.ID, Collaborate: util.OptionalBoolFalse, TopicOnly: topicOnly, @@ -191,14 +193,16 @@ func Profile(ctx *context.Context) { total = int(count) default: repos, count, err = models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: models.ListOptions{ + PageSize: setting.UI.User.RepoPagingNum, + Page: page, + }, Actor: ctx.User, Keyword: keyword, OwnerID: ctxUser.ID, OrderBy: orderBy, Private: ctx.IsSigned, - Page: page, IsProfile: true, - PageSize: setting.UI.User.RepoPagingNum, Collaborate: util.OptionalBoolFalse, TopicOnly: topicOnly, IncludeDescription: setting.UI.SearchRepoDescription, diff --git a/routers/user/setting/applications.go b/routers/user/setting/applications.go index d93684bcc0..e7bf612269 100644 --- a/routers/user/setting/applications.go +++ b/routers/user/setting/applications.go @@ -68,7 +68,7 @@ func DeleteApplication(ctx *context.Context) { } func loadApplicationsData(ctx *context.Context) { - tokens, err := models.ListAccessTokens(ctx.User.ID) + tokens, err := models.ListAccessTokens(ctx.User.ID, models.ListOptions{}) if err != nil { ctx.ServerError("ListAccessTokens", err) return diff --git a/routers/user/setting/keys.go b/routers/user/setting/keys.go index c62b117a76..3475299437 100644 --- a/routers/user/setting/keys.go +++ b/routers/user/setting/keys.go @@ -133,14 +133,14 @@ func DeleteKey(ctx *context.Context) { } func loadKeysData(ctx *context.Context) { - keys, err := models.ListPublicKeys(ctx.User.ID) + keys, err := models.ListPublicKeys(ctx.User.ID, models.ListOptions{}) if err != nil { ctx.ServerError("ListPublicKeys", err) return } ctx.Data["Keys"] = keys - gpgkeys, err := models.ListGPGKeys(ctx.User.ID) + gpgkeys, err := models.ListGPGKeys(ctx.User.ID, models.ListOptions{}) if err != nil { ctx.ServerError("ListGPGKeys", err) return diff --git a/routers/user/setting/profile.go b/routers/user/setting/profile.go index 6db9fc7c6e..a5cc433a9a 100644 --- a/routers/user/setting/profile.go +++ b/routers/user/setting/profile.go @@ -196,7 +196,7 @@ func Repos(ctx *context.Context) { ctxUser := ctx.User var err error - if err = ctxUser.GetRepositories(1, setting.UI.User.RepoPagingNum); err != nil { + if err = ctxUser.GetRepositories(models.ListOptions{Page: 1, PageSize: setting.UI.User.RepoPagingNum}); err != nil { ctx.ServerError("GetRepositories", err) return } diff --git a/routers/user/setting/security.go b/routers/user/setting/security.go index f8f5cc0cd8..c7c3226c9b 100644 --- a/routers/user/setting/security.go +++ b/routers/user/setting/security.go @@ -71,7 +71,7 @@ func loadSecurityData(ctx *context.Context) { ctx.Data["RequireU2F"] = true } - tokens, err := models.ListAccessTokens(ctx.User.ID) + tokens, err := models.ListAccessTokens(ctx.User.ID, models.ListOptions{}) if err != nil { ctx.ServerError("ListAccessTokens", err) return |