2016-10-02 23:12:59 -04:00
|
|
|
module API
|
|
|
|
# Boards API
|
|
|
|
class Boards < Grape::API
|
|
|
|
before { authenticate! }
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
resource :projects do
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Get all project boards' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::Board
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
get ':id/boards' do
|
|
|
|
authorize!(:read_board, user_project)
|
2016-10-06 16:36:46 -04:00
|
|
|
present user_project.boards, with: Entities::Board
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
params do
|
|
|
|
requires :board_id, type: Integer, desc: 'The ID of a board'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
segment ':id/boards/:board_id' do
|
|
|
|
helpers do
|
|
|
|
def project_board
|
2016-10-06 16:36:46 -04:00
|
|
|
board = user_project.boards.first
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
if params[:board_id] == board.id
|
2016-10-02 23:12:59 -04:00
|
|
|
board
|
|
|
|
else
|
|
|
|
not_found!('Board')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def board_lists
|
|
|
|
project_board.lists.destroyable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Get the lists of a project board' do
|
|
|
|
detail 'Does not include `backlog` and `done` lists. This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
get '/lists' do
|
|
|
|
authorize!(:read_board, user_project)
|
|
|
|
present board_lists, with: Entities::List
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Get a list of a project board' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :list_id, type: Integer, desc: 'The ID of a list'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
get '/lists/:list_id' do
|
|
|
|
authorize!(:read_board, user_project)
|
|
|
|
present board_lists.find(params[:list_id]), with: Entities::List
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Create a new board list' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :label_id, type: Integer, desc: 'The ID of an existing label'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
post '/lists' do
|
2016-10-13 17:48:59 -04:00
|
|
|
unless available_labels.exists?(params[:label_id])
|
|
|
|
render_api_error!({ error: 'Label not found!' }, 400)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
authorize!(:admin_list, user_project)
|
|
|
|
|
2016-10-06 16:36:46 -04:00
|
|
|
service = ::Boards::Lists::CreateService.new(user_project, current_user,
|
|
|
|
{ label_id: params[:label_id] })
|
|
|
|
|
|
|
|
list = service.execute(project_board)
|
2016-10-02 23:12:59 -04:00
|
|
|
|
|
|
|
if list.valid?
|
|
|
|
present list, with: Entities::List
|
|
|
|
else
|
|
|
|
render_validation_error!(list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Moves a board list to a new position' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :list_id, type: Integer, desc: 'The ID of a list'
|
|
|
|
requires :position, type: Integer, desc: 'The position of the list'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
put '/lists/:list_id' do
|
|
|
|
list = project_board.lists.movable.find(params[:list_id])
|
|
|
|
|
|
|
|
authorize!(:admin_list, user_project)
|
|
|
|
|
2016-10-06 16:36:46 -04:00
|
|
|
service = ::Boards::Lists::MoveService.new(user_project, current_user,
|
2016-10-14 03:38:20 -04:00
|
|
|
{ position: params[:position] })
|
2016-10-02 23:12:59 -04:00
|
|
|
|
2016-10-06 16:36:46 -04:00
|
|
|
if service.execute(list)
|
2016-10-02 23:12:59 -04:00
|
|
|
present list, with: Entities::List
|
|
|
|
else
|
|
|
|
render_api_error!({ error: "List could not be moved!" }, 400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Delete a board list' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :list_id, type: Integer, desc: 'The ID of a board list'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
delete "/lists/:list_id" do
|
|
|
|
authorize!(:admin_list, user_project)
|
|
|
|
|
2016-10-06 16:36:46 -04:00
|
|
|
list = board_lists.find(params[:list_id])
|
|
|
|
|
|
|
|
service = ::Boards::Lists::DestroyService.new(user_project, current_user)
|
|
|
|
|
|
|
|
if service.execute(list)
|
|
|
|
present list, with: Entities::List
|
2016-10-02 23:12:59 -04:00
|
|
|
else
|
2016-10-06 16:36:46 -04:00
|
|
|
render_api_error!({ error: 'List could not be deleted!' }, 400)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|