summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user
diff options
context:
space:
mode:
authorSpaWn2KiLl <SpaWn2KiLl@users.noreply.github.com>2020-01-24 19:00:29 +0000
committertechknowlogick <techknowlogick@gitea.io>2020-01-24 14:00:29 -0500
commit1f01f53c53ea75634f981611635be49c69e1920b (patch)
treedd99285ba1d9a8a888f8deccef7865e53901d859 /routers/api/v1/user
parent333401e0fdca1abe096257479e7090c6e69985ec (diff)
downloadgitea-1f01f53c53ea75634f981611635be49c69e1920b.tar.gz
gitea-1f01f53c53ea75634f981611635be49c69e1920b.zip
API add/generalize pagination (#9452)
* paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r--routers/api/v1/user/app.go11
-rw-r--r--routers/api/v1/user/follower.go40
-rw-r--r--routers/api/v1/user/gpg_key.go26
-rw-r--r--routers/api/v1/user/key.go19
-rw-r--r--routers/api/v1/user/repo.go38
-rw-r--r--routers/api/v1/user/star.go27
-rw-r--r--routers/api/v1/user/user.go16
-rw-r--r--routers/api/v1/user/watch.go26
8 files changed, 180 insertions, 23 deletions
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)
}