Commit 52c22b4a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Allow filtering by weight in issues API

parent c5f8a7df
......@@ -42,6 +42,7 @@ GET /issues?my_reaction_emoji=star
| `author_id` | integer | no | Return issues created by the given user `id`. Combine with `scope=all` or `scope=assigned_to_me`. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Return issues assigned to the given user `id`. `None` returns unassigned issues. `Any` returns issues with an assignee. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `my_reaction_emoji` | string | no | Return issues reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `weight` | integer | no | Return issues with the specified `weight`. `None` returns issues with no weight assigned. `Any` returns issues with a weight assigned. |
| `iids[]` | Array[integer] | no | Return only the issues having the given `iid` |
| `order_by` | string | no | Return issues ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return issues sorted in `asc` or `desc` order. Default is `desc` |
......@@ -157,6 +158,7 @@ GET /groups/:id/issues?my_reaction_emoji=star
| `author_id` | integer | no | Return issues created by the given user `id` _([Introduced][ce-13004] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Return issues assigned to the given user `id`. `None` returns unassigned issues. `Any` returns issues with an assignee. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `my_reaction_emoji` | string | no | Return issues reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `weight` | integer | no | Return issues with the specified `weight`. `None` returns issues with no weight assigned. `Any` returns issues with a weight assigned. |
| `order_by` | string | no | Return issues ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return issues sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Search group issues against their `title` and `description` |
......@@ -272,6 +274,7 @@ GET /projects/:id/issues?my_reaction_emoji=star
| `author_id` | integer | no | Return issues created by the given user `id` _([Introduced][ce-13004] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Return issues assigned to the given user `id`. `None` returns unassigned issues. `Any` returns issues with an assignee. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `my_reaction_emoji` | string | no | Return issues reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `weight` | integer | no | Return issues with the specified `weight`. `None` returns issues with no weight assigned. `Any` returns issues with a weight assigned. |
| `order_by` | string | no | Return issues ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return issues sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Search project issues against their `title` and `description` |
......
......@@ -39,11 +39,11 @@ module EE
end
def filter_by_no_weight?
params[:weight] == ::Issue::WEIGHT_NONE
params[:weight].to_s.downcase == FILTER_NONE
end
def filter_by_any_weight?
params[:weight] == ::Issue::WEIGHT_ANY
params[:weight].to_s.downcase == FILTER_ANY
end
override :by_assignee
......
......@@ -36,6 +36,34 @@ describe API::Issues, :mailer do
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/issues', dir: 'ee')
end
describe "filtering by weight" do
before do
issue2 = create(:issue, author: user2, project: project, weight: 5)
create(:issue, author: user2, project: project, weight: 1)
create(:issue, author: user2, project: project, weight: 3)
end
it 'returns issues with specific weight' do
get api('/issues', user), weight: 5, scope: 'all'
expect_paginated_array_response(size: 1)
expect(first_issue['id']).to eq(issue2.id)
end
it 'returns issues with no weight' do
get api('/issues', user), weight: 'None', scope: 'all'
expect_paginated_array_response(size: 1)
expect(first_issue['id']).to eq(issue.id)
end
it 'returns issues with any weight' do
get api('/issues', user), weight: 'Any', scope: 'all'
expect_paginated_array_response(size: 3)
end
end
end
end
......
......@@ -60,7 +60,7 @@ module API
end
params :issue_params_ee do
optional :weight, type: Integer, desc: 'The weight of the issue'
optional :weight, type: [Integer, String], integer_none_any: true, desc: 'The weight of the issue'
end
params :issue_params do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment