Skip to content

Commit

Permalink
Merge pull request #1 from 6543-forks/fixed_count_of_filteredIssues_f…
Browse files Browse the repository at this point in the history
…ormat

format code
  • Loading branch information
hinoshiba authored Jul 23, 2020
2 parents 0211cb5 + bc8cc31 commit 7a6de11
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ func SearchIssues(ctx *context.APIContext) {
var labelIDs []int64
var err error
if len(keyword) > 0 && len(repoIDs) > 0 {
issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword)
if err != nil {
if issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword); err != nil {
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err)
return
}
Expand All @@ -157,6 +156,10 @@ 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 {
issuesOpt := &models.IssuesOptions{
ListOptions: models.ListOptions{
Page: ctx.QueryInt("page"),
PageSize: setting.UI.IssuePagingNum,
},
RepoIDs: repoIDs,
IsClosed: isClosed,
IssueIDs: issueIDs,
Expand All @@ -166,12 +169,7 @@ func SearchIssues(ctx *context.APIContext) {
IsPull: isPull,
}

issuesOpt.ListOptions = models.ListOptions{
Page: ctx.QueryInt("page"),
PageSize: setting.UI.IssuePagingNum,
}
issues, err = models.Issues(issuesOpt)
if err != nil {
if issues, err = models.Issues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "Issues", err)
return
}
Expand All @@ -180,8 +178,7 @@ func SearchIssues(ctx *context.APIContext) {
Page: 0,
PageSize: issueCount,
}
filteredCount, err = models.CountIssues(issuesOpt)
if err != nil {
if filteredCount, err = models.CountIssues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "CountIssues", err)
return
}
Expand Down Expand Up @@ -326,6 +323,7 @@ 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 {
issuesOpt := &models.IssuesOptions{
ListOptions: listOptions,
RepoIDs: []int64{ctx.Repo.Repository.ID},
IsClosed: isClosed,
IssueIDs: issueIDs,
Expand All @@ -334,9 +332,7 @@ func ListIssues(ctx *context.APIContext) {
IsPull: isPull,
}

issuesOpt.ListOptions = listOptions
issues, err = models.Issues(issuesOpt)
if err != nil {
if issues, err = models.Issues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "Issues", err)
return
}
Expand All @@ -345,16 +341,14 @@ func ListIssues(ctx *context.APIContext) {
Page: 0,
PageSize: ctx.Repo.Repository.NumIssues,
}
filteredCount, err = models.CountIssues(issuesOpt)
if err != nil {
if filteredCount, err = models.CountIssues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "CountIssues", err)
return
}
}

ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount))

ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
}

Expand Down

0 comments on commit 7a6de11

Please sign in to comment.