diff options
author | Fabio Busatto <fabio@gitlab.com> | 2019-03-27 12:01:07 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-03-27 12:01:07 +0300 |
commit | 035c8af12e4ea6dbba18255214bad2a53c1b1cf1 (patch) | |
tree | fc20eba28a847b6a7d65886dc864450198a75a77 /lib | |
parent | 978aa04f30185b5a4adaa5e26d4a9674a8d37811 (diff) |
Resolve "Get milestone by title via API"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers.rb | 6 | ||||
-rw-r--r-- | lib/api/milestone_responses.rb | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index b8bd180bdc1..8a21d44b4bf 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -302,6 +302,12 @@ module API end # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord + def filter_by_title(items, title) + items.where(title: title) + end + # rubocop: enable CodeReuse/ActiveRecord + def filter_by_search(items, text) items.search(text) end diff --git a/lib/api/milestone_responses.rb b/lib/api/milestone_responses.rb index a0ca39b69d4..62e159ab003 100644 --- a/lib/api/milestone_responses.rb +++ b/lib/api/milestone_responses.rb @@ -16,6 +16,7 @@ module API optional :state, type: String, values: %w[active closed all], default: 'all', desc: 'Return "active", "closed", or "all" milestones' optional :iids, type: Array[Integer], desc: 'The IIDs of the milestones' + optional :title, type: String, desc: 'The title of the milestones' optional :search, type: String, desc: 'The search criteria for the title or description of the milestone' use :pagination end @@ -33,6 +34,7 @@ module API milestones = parent.milestones.order_id_desc milestones = Milestone.filter_by_state(milestones, params[:state]) milestones = filter_by_iid(milestones, params[:iids]) if params[:iids].present? + milestones = filter_by_title(milestones, params[:title]) if params[:title] milestones = filter_by_search(milestones, params[:search]) if params[:search] present paginate(milestones), with: Entities::Milestone |