Add an endpoint to generate the default lists for a board

parent 68cfdba7
...@@ -33,6 +33,16 @@ class Projects::BoardListsController < Projects::ApplicationController ...@@ -33,6 +33,16 @@ class Projects::BoardListsController < Projects::ApplicationController
end end
end end
def generate
service = Boards::Lists::GenerateService.new(project, current_user)
if service.execute
render json: project.board.lists.label.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :color] } })
else
head :unprocessable_entity
end
end
private private
def list_params def list_params
......
...@@ -860,6 +860,10 @@ Rails.application.routes.draw do ...@@ -860,6 +860,10 @@ Rails.application.routes.draw do
resources :issues, only: [:update], controller: :board_issues resources :issues, only: [:update], controller: :board_issues
resources :lists, only: [:create, :update, :destroy], controller: :board_lists do resources :lists, only: [:create, :update, :destroy], controller: :board_lists do
collection do
post :generate
end
resources :issues, only: [:index], controller: :board_issues resources :issues, only: [:index], controller: :board_issues
end end
end end
......
...@@ -119,4 +119,36 @@ describe Projects::BoardListsController do ...@@ -119,4 +119,36 @@ describe Projects::BoardListsController do
format: :json format: :json
end end
end end
describe 'POST #generate' do
context 'when board lists is empty' do
it 'returns a successful 200 response' do
generate_default_board_lists
expect(response).to have_http_status(200)
end
it 'returns the defaults lists' do
generate_default_board_lists
expect(response).to match_response_schema('list', array: true)
end
end
context 'when board lists is not empty' do
it 'returns a unprocessable entity 422 response' do
create(:list, board: board)
generate_default_board_lists
expect(response).to have_http_status(422)
end
end
def generate_default_board_lists
post :generate, namespace_id: project.namespace.to_param,
project_id: project.to_param,
format: :json
end
end
end end
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