diff options
author | Lanre Adelowo <adelowomailbox@gmail.com> | 2019-06-06 01:37:45 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-06-06 08:37:45 +0800 |
commit | de6539fc8c37485afcd6f30092a9ccbc3cae7de5 (patch) | |
tree | 02aec172ffe99ac123b56b301c70774f1f3f1292 /models/issue_milestone.go | |
parent | 59e6a7b97f503c12ef2a6096ca7f127f81521b7a (diff) | |
download | gitea-de6539fc8c37485afcd6f30092a9ccbc3cae7de5.tar.gz gitea-de6539fc8c37485afcd6f30092a9ccbc3cae7de5.zip |
Add state param to milestone listing API (#7131)
* Support state params
* update tests
* fix tests
* add state=all support
* update tests
* update swagger
* update swagger
Diffstat (limited to 'models/issue_milestone.go')
-rw-r--r-- | models/issue_milestone.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go index 3bde4b558c..f279dda195 100644 --- a/models/issue_milestone.go +++ b/models/issue_milestone.go @@ -190,10 +190,26 @@ func (milestones MilestoneList) getMilestoneIDs() []int64 { } // GetMilestonesByRepoID returns all opened milestones of a repository. -func GetMilestonesByRepoID(repoID int64) (MilestoneList, error) { +func GetMilestonesByRepoID(repoID int64, state api.StateType) (MilestoneList, error) { + + sess := x.Where("repo_id = ?", repoID) + + switch state { + case api.StateClosed: + sess = sess.And("is_closed = ?", true) + + case api.StateAll: + break + + case api.StateOpen: + fallthrough + + default: + sess = sess.And("is_closed = ?", false) + } + miles := make([]*Milestone, 0, 10) - return miles, x.Where("repo_id = ? AND is_closed = ?", repoID, false). - Asc("deadline_unix").Asc("id").Find(&miles) + return miles, sess.Asc("deadline_unix").Asc("id").Find(&miles) } // GetMilestones returns a list of milestones of given repository and status. |