[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
This commit is contained in:
6543 2021-08-12 14:43:08 +02:00 committed by GitHub
parent ca13e1d56c
commit 2289580bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 637 additions and 329 deletions

View file

@ -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.Error(http.StatusInternalServerError, "ListAccessTokens", err)
ctx.InternalServerError(err)
return
}
tokens, err := models.ListAccessTokens(opts)
if err != nil {
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)
}