diff options
-rw-r--r-- | app/controllers/projects/board_issues_controller.rb | 22 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | spec/controllers/projects/board_issues_controller_spec.rb | 46 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/issue.json | 30 |
4 files changed, 99 insertions, 0 deletions
diff --git a/app/controllers/projects/board_issues_controller.rb b/app/controllers/projects/board_issues_controller.rb new file mode 100644 index 00000000000..fb77270adda --- /dev/null +++ b/app/controllers/projects/board_issues_controller.rb @@ -0,0 +1,22 @@ +class Projects::BoardIssuesController < Projects::ApplicationController + respond_to :json + + rescue_from ActiveRecord::RecordNotFound, with: :record_not_found + + def index + issues = Boards::Issues::ListService.new(project, current_user, filter_params).execute + issues = issues.page(params[:page]) + + render json: issues.as_json(only: [:id, :title, :confidential], include: { labels: { only: [:id, :title, :color] } }) + end + + private + + def filter_params + params.permit(:list_id) + end + + def record_not_found(exception) + render json: { error: exception.message }, status: :not_found + end +end diff --git a/config/routes.rb b/config/routes.rb index 9a56e39010f..7c14aba5644 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -857,6 +857,7 @@ Rails.application.routes.draw do end resource :board, only: [:show] do + resources :issues, only: [:index], controller: :board_issues resources :lists, only: [:create, :update, :destroy], controller: :board_lists end diff --git a/spec/controllers/projects/board_issues_controller_spec.rb b/spec/controllers/projects/board_issues_controller_spec.rb new file mode 100644 index 00000000000..64c98443caa --- /dev/null +++ b/spec/controllers/projects/board_issues_controller_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Projects::BoardIssuesController do + let(:project) { create(:project_with_board) } + let(:user) { create(:user) } + + before do + project.team << [user, :master] + sign_in(user) + end + + describe 'GET #index' do + context 'with valid list id' do + it 'returns issues that have the list label applied' do + label1 = create(:label, project: project, name: 'Planning') + label2 = create(:label, project: project, name: 'Development') + + create(:labeled_issue, project: project, labels: [label1]) + create(:labeled_issue, project: project, labels: [label2]) + create(:labeled_issue, project: project, labels: [label2]) + + create(:list, board: project.board, label: label1, position: 1) + development = create(:list, board: project.board, label: label2, position: 2) + + get :index, namespace_id: project.namespace.to_param, + project_id: project.to_param, + list_id: development.to_param + + parsed_response = JSON.parse(response.body) + + expect(response).to match_response_schema('issue', array: true) + expect(parsed_response.length).to eq 2 + end + end + + context 'with invalid list id' do + it 'returns a not found 404 response' do + get :index, namespace_id: project.namespace.to_param, + project_id: project.to_param, + id: 999 + + expect(response).to have_http_status(404) + end + end + end +end diff --git a/spec/fixtures/api/schemas/issue.json b/spec/fixtures/api/schemas/issue.json new file mode 100644 index 00000000000..666e0cdf82c --- /dev/null +++ b/spec/fixtures/api/schemas/issue.json @@ -0,0 +1,30 @@ +{ + "type": "object", + "required" : [ + "id", + "title", + "confidential" + ], + "properties" : { + "id": { "type": "integer" }, + "title": { "type": "string" }, + "confidential": { "type": "boolean" }, + "labels": { + "type": ["array"], + "required": [ + "id", + "color", + "title" + ], + "properties": { + "id": { "type": "integer" }, + "color": { + "type": "string", + "pattern": "^#[0-9A-Fa-f]{3}{1,2}+$" + }, + "title": { "type": "string" } + } + } + }, + "additionalProperties": false +} |