aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/app.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-08-12 14:43:08 +0200
committerGitHub <noreply@github.com>2021-08-12 14:43:08 +0200
commit2289580bb7ef8dfa4124c2b3bfb89897dbb35f46 (patch)
treee68aae604bb3d738b44156504a1415adaf042c68 /routers/api/v1/user/app.go
parentca13e1d56c561f72cf8ad251fe61b1898abfec51 (diff)
downloadgitea-2289580bb7ef8dfa4124c2b3bfb89897dbb35f46.tar.gz
gitea-2289580bb7ef8dfa4124c2b3bfb89897dbb35f46.zip
[API] generalize list header (#16551)
* Add info about list endpoints to CONTRIBUTING.md * Let all list endpoints return X-Total-Count header * Add TODOs for GetCombinedCommitStatusByRef * Fix models/issue_stopwatch.go * Rrefactor models.ListDeployKeys * Introduce helper func and use them for SetLinkHeader related func
Diffstat (limited to 'routers/api/v1/user/app.go')
-rw-r--r--routers/api/v1/user/app.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go
index afd209f2f0..f0f7cb4159 100644
--- a/routers/api/v1/user/app.go
+++ b/routers/api/v1/user/app.go
@@ -44,9 +44,16 @@ func ListAccessTokens(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/AccessTokenList"
- tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID, ListOptions: utils.GetListOptions(ctx)})
+ opts := models.ListAccessTokensOptions{UserID: ctx.User.ID, ListOptions: utils.GetListOptions(ctx)}
+
+ count, err := models.CountAccessTokens(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+ tokens, err := models.ListAccessTokens(opts)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "ListAccessTokens", err)
+ ctx.InternalServerError(err)
return
}
@@ -58,6 +65,8 @@ func ListAccessTokens(ctx *context.APIContext) {
TokenLastEight: tokens[i].TokenLastEight,
}
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, &apiTokens)
}
@@ -242,7 +251,7 @@ func ListOauth2Applications(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/OAuth2ApplicationList"
- apps, err := models.ListOAuth2Applications(ctx.User.ID, utils.GetListOptions(ctx))
+ apps, total, err := models.ListOAuth2Applications(ctx.User.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err)
return
@@ -253,6 +262,8 @@ func ListOauth2Applications(ctx *context.APIContext) {
apiApps[i] = convert.ToOAuth2Application(apps[i])
apiApps[i].ClientSecret = "" // Hide secret on application list
}
+
+ ctx.SetTotalCountHeader(total)
ctx.JSON(http.StatusOK, &apiApps)
}