diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2017-01-04 09:23:46 +0100 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2017-01-04 09:50:09 +0100 |
commit | dc6b35e1ae2c1e4c8e4dc72c8ff50b6c4b0068ce (patch) | |
tree | 472b1438ae4ce96cebac9b18c13798bdc84aea32 /lib | |
parent | 115aac77f614a9130aa9bc6ff48aed47339aebfc (diff) | |
download | gitlab-ce-dc6b35e1ae2c1e4c8e4dc72c8ff50b6c4b0068ce.tar.gz |
Refactor issues filter in API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/issues.rb | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 91f65882f47..ba02f0c91b3 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -5,22 +5,11 @@ module API before { authenticate! } helpers do - def filter_issues_state(issues, state) - case state - when 'opened' then issues.opened - when 'closed' then issues.closed - else issues - end - end - + # TODO: Remove in 9.0 and switch to IssueFinder-based label filtering def filter_issues_labels(issues, labels) issues.includes(:labels).where('labels.title' => labels.split(',')) end - def filter_issues_milestone(issues, milestone) - issues.includes(:milestone).where('milestones.title' => milestone) - end - params :issues_params do optional :labels, type: String, desc: 'Comma-separated list of label names' optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at', @@ -50,8 +39,7 @@ module API use :issues_params end get do - issues = current_user.issues.inc_notes_with_associations - issues = filter_issues_state(issues, params[:state]) + issues = IssuesFinder.new(current_user, scope: 'all', author_id: current_user.id, state: params[:state]).execute.inc_notes_with_associations issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? issues = issues.reorder(params[:order_by] => params[:sort]) @@ -99,16 +87,14 @@ module API use :issues_params end get ":id/issues" do - issues = IssuesFinder.new(current_user, project_id: user_project.id).execute.inc_notes_with_associations - issues = filter_issues_state(issues, params[:state]) + issues = IssuesFinder.new(current_user, + project_id: user_project.id, + state: params[:state], + milestone_title: params[:milestone]).execute.inc_notes_with_associations issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? issues = filter_by_iid(issues, params[:iid]) unless params[:iid].nil? - - unless params[:milestone].nil? - issues = filter_issues_milestone(issues, params[:milestone]) - end - issues = issues.reorder(params[:order_by] => params[:sort]) + present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project end |