diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2016-04-06 14:03:07 +0300 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2016-04-06 21:39:43 +0300 |
commit | 0728588c3424fd7e75ca3c45ad1ea84063437311 (patch) | |
tree | e7286603c62774fc6d4932b287c6baaab2e685ea /lib/api/milestones.rb | |
parent | 77e178b5e13633090307afa915eea50927fdabda (diff) |
API: Ability to filter milestones by state
Diffstat (limited to 'lib/api/milestones.rb')
-rw-r--r-- | lib/api/milestones.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index c5cd73943fb..39efa1b176b 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -3,17 +3,33 @@ module API class Milestones < Grape::API before { authenticate! } + helpers do + def filter_milestones_state(milestones, state) + case state + when 'active' then milestones.active + when 'closed' then milestones.closed + else milestones + end + end + end + resource :projects do # Get a list of project milestones # # Parameters: - # id (required) - The ID of a project + # id (required) - The ID of a project + # state (optional) - Return "active" or "closed" milestones # Example Request: # GET /projects/:id/milestones + # GET /projects/:id/milestones?state=active + # GET /projects/:id/milestones?state=closed get ":id/milestones" do authorize! :read_milestone, user_project - present paginate(user_project.milestones), with: Entities::Milestone + milestones = user_project.milestones + milestones = filter_milestones_state(milestones, params[:state]) unless params[:state].nil? + + present paginate(milestones), with: Entities::Milestone end # Get a single project milestone |