diff options
author | Lauris BH <lauris@nix.lv> | 2017-06-29 18:11:38 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-29 23:11:38 +0800 |
commit | 783b1967e257fdba2bd593d9f2108da2010b7448 (patch) | |
tree | ce6b942c92ee7a45ffbca29cdd1dd0dae3964df8 /models/release.go | |
parent | 33f3165296613c819ed82612da2f6738c1301ec1 (diff) | |
download | gitea-783b1967e257fdba2bd593d9f2108da2010b7448.tar.gz gitea-783b1967e257fdba2bd593d9f2108da2010b7448.zip |
Fix release display and correct paging (#2080)
Diffstat (limited to 'models/release.go')
-rw-r--r-- | models/release.go | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/models/release.go b/models/release.go index 783f1f0475..f12fc06840 100644 --- a/models/release.go +++ b/models/release.go @@ -233,40 +233,44 @@ func GetReleaseByID(id int64) (*Release, error) { return rel, nil } -// GetReleasesByRepoID returns a list of releases of repository. -func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err error) { - if page <= 0 { - page = 1 - } - err = x. - Desc("created_unix"). - Limit(pageSize, (page-1)*pageSize). - Find(&rels, Release{RepoID: repoID}) - return rels, err +// FindReleasesOptions describes the conditions to Find releases +type FindReleasesOptions struct { + IncludeDrafts bool + TagNames []string } -// GetReleaseCountByRepoID returns the count of releases of repository -func GetReleaseCountByRepoID(repoID int64, includeDrafts bool) (int64, error) { +func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond { var cond = builder.NewCond() cond = cond.And(builder.Eq{"repo_id": repoID}) - if includeDrafts { - return x.Where(cond).Count(&Release{}) + if !opts.IncludeDrafts { + cond = cond.And(builder.Eq{"is_draft": false}) } - - cond = cond.And(builder.Eq{"is_draft": false}) - return x.Where(cond).Count(&Release{}) + if len(opts.TagNames) > 0 { + cond = cond.And(builder.In("tag_name", opts.TagNames)) + } + return cond } -// GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames. -func GetReleasesByRepoIDAndNames(repoID int64, tagNames []string) (rels []*Release, err error) { +// GetReleasesByRepoID returns a list of releases of repository. +func GetReleasesByRepoID(repoID int64, opts FindReleasesOptions, page, pageSize int) (rels []*Release, err error) { + if page <= 0 { + page = 1 + } + err = x. - Desc("created_unix"). - In("tag_name", tagNames). - Find(&rels, Release{RepoID: repoID}) + Desc("created_unix", "id"). + Limit(pageSize, (page-1)*pageSize). + Where(opts.toConds(repoID)). + Find(&rels) return rels, err } +// GetReleaseCountByRepoID returns the count of releases of repository +func GetReleaseCountByRepoID(repoID int64, opts FindReleasesOptions) (int64, error) { + return x.Where(opts.toConds(repoID)).Count(&Release{}) +} + type releaseMetaSearch struct { ID []int64 Rel []*Release |