diff options
author | iszla <iszla@users.noreply.github.com> | 2017-06-28 16:47:00 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-28 22:47:00 +0800 |
commit | 3f9016430f5a712bdff05a9cc941a287be0f217d (patch) | |
tree | 874a5bb1a3823a7e74590a6212968ea12384fe25 /models/release.go | |
parent | 1f4d84b7b26c08e5a0e3abbaac650ac39d48c9d3 (diff) | |
download | gitea-3f9016430f5a712bdff05a9cc941a287be0f217d.tar.gz gitea-3f9016430f5a712bdff05a9cc941a287be0f217d.zip |
Pagination on releases page (#2035)
* Added count to GetReleasesByRepoID so pagination will work
* Separated it out to a new function, can then also leave the API part unaffected
* Remove extra whitespace added in untouched function
* Added comment and corrected name in error handler
* Account for if the user is owner or not in the count
* Also check if repo is draft
* revert back to the correct count in the ReleasesToDisplay loop
* Fixed lint error regarding else with return statement
* Use Cond struct instead of string, corrected name in error handler
* Removed unused return variable names
Diffstat (limited to 'models/release.go')
-rw-r--r-- | models/release.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/models/release.go b/models/release.go index bc48f61596..783f1f0475 100644 --- a/models/release.go +++ b/models/release.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/sdk/gitea" + "github.com/go-xorm/builder" "github.com/go-xorm/xorm" ) @@ -244,6 +245,19 @@ func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err return rels, err } +// GetReleaseCountByRepoID returns the count of releases of repository +func GetReleaseCountByRepoID(repoID int64, includeDrafts bool) (int64, error) { + var cond = builder.NewCond() + cond = cond.And(builder.Eq{"repo_id": repoID}) + + if includeDrafts { + return x.Where(cond).Count(&Release{}) + } + + cond = cond.And(builder.Eq{"is_draft": false}) + return x.Where(cond).Count(&Release{}) +} + // GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames. func GetReleasesByRepoIDAndNames(repoID int64, tagNames []string) (rels []*Release, err error) { err = x. |