mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
Add missing X-Total-Count
and fix some related bugs (#17968)
* Add missing `X-Total-Count` and fix some related bugs
Adds `X-Total-Count` header to APIs that return a list but doesn't have it yet.
Fixed bugs:
* not returned after reporting error (39eb82446c/routers/api/v1/user/star.go (L70)
)
* crash with index out of bounds, API issue/issueSubscriptions
I also found various endpoints that return lists but do not apply/support pagination yet:
```
/repos/{owner}/{repo}/issues/{index}/labels
/repos/{owner}/{repo}/issues/comments/{id}/reactions
/repos/{owner}/{repo}/branch_protections
/repos/{owner}/{repo}/contents
/repos/{owner}/{repo}/hooks/git
/repos/{owner}/{repo}/issue_templates
/repos/{owner}/{repo}/releases/{id}/assets
/repos/{owner}/{repo}/reviewers
/repos/{owner}/{repo}/teams
/user/emails
/users/{username}/heatmap
```
If this is not expected, an new issue should be opened.
Closes #13043
* fmt
* Update routers/api/v1/repo/issue_subscription.go
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Use FindAndCount
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
790e6cfeec
commit
9d943bf374
24 changed files with 73 additions and 36 deletions
|
@ -509,6 +509,7 @@ func GetTeamRepos(ctx *context.APIContext) {
|
|||
}
|
||||
repos[i] = convert.ToRepo(repo, access)
|
||||
}
|
||||
ctx.SetTotalCountHeader(int64(team.NumRepos))
|
||||
ctx.JSON(http.StatusOK, repos)
|
||||
}
|
||||
|
||||
|
|
|
@ -67,9 +67,9 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
reactions, err := models.FindCommentReactions(comment)
|
||||
reactions, _, err := models.FindCommentReactions(comment)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err)
|
||||
ctx.Error(http.StatusInternalServerError, "FindCommentReactions", err)
|
||||
return
|
||||
}
|
||||
_, err = reactions.LoadUsers(ctx.Repo.Repository)
|
||||
|
@ -285,7 +285,7 @@ func GetIssueReactions(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
reactions, err := models.FindIssueReactions(issue, utils.GetListOptions(ctx))
|
||||
reactions, count, err := models.FindIssueReactions(issue, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err)
|
||||
return
|
||||
|
@ -305,6 +305,7 @@ func GetIssueReactions(ctx *context.APIContext) {
|
|||
})
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
|
|
|
@ -279,9 +279,16 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
apiUsers := make([]*api.User, 0, len(users))
|
||||
for i := range users {
|
||||
apiUsers[i] = convert.ToUser(users[i], ctx.User)
|
||||
for _, v := range users {
|
||||
apiUsers = append(apiUsers, convert.ToUser(v, ctx.User))
|
||||
}
|
||||
|
||||
count, err := models.CountIssueWatchers(issue.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountIssueWatchers", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, apiUsers)
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
|
|||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
statuses, err := models.GetLatestCommitStatus(repo.ID, sha, utils.GetListOptions(ctx))
|
||||
statuses, count, err := models.GetLatestCommitStatus(repo.ID, sha, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err))
|
||||
return
|
||||
|
@ -266,6 +266,6 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
|
|||
|
||||
combiStatus := convert.ToCombinedStatus(statuses, convert.ToRepo(repo, ctx.Repo.AccessMode))
|
||||
|
||||
// TODO: ctx.SetTotalCountHeader(count)
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, combiStatus)
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ func GetTree(ctx *context.APIContext) {
|
|||
if tree, err := files_service.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
|
||||
ctx.Error(http.StatusBadRequest, "", err.Error())
|
||||
} else {
|
||||
ctx.SetTotalCountHeader(int64(tree.TotalCount))
|
||||
ctx.JSON(http.StatusOK, tree)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,6 +323,7 @@ func ListWikiPages(ctx *context.APIContext) {
|
|||
pages = append(pages, convert.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(int64(len(entries)))
|
||||
ctx.JSON(http.StatusOK, pages)
|
||||
}
|
||||
|
||||
|
@ -432,6 +433,7 @@ func ListPageRevisions(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(commitsCount)
|
||||
ctx.JSON(http.StatusOK, convert.ToWikiCommitList(commitsHistory, commitsCount))
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,10 @@ func GetStarredRepos(ctx *context.APIContext) {
|
|||
repos, err := getStarredRepos(user, private, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(int64(user.NumStars))
|
||||
ctx.JSON(http.StatusOK, &repos)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue