Add endpoint to list issues for a specific board list

parent 52b6a7e9
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
......@@ -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
......
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
{
"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
}
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