BigW Consortium Gitlab

Update Issue Board API to handle with has_many association

parent 1a2002d9
...@@ -7,13 +7,14 @@ module API ...@@ -7,13 +7,14 @@ module API
# Get the project board # Get the project board
get ':id/boards' do get ':id/boards' do
authorize!(:read_board, user_project) authorize!(:read_board, user_project)
present [user_project.board], with: Entities::Board present user_project.boards, with: Entities::Board
end end
segment ':id/boards/:board_id' do segment ':id/boards/:board_id' do
helpers do helpers do
def project_board def project_board
board = user_project.board board = user_project.boards.first
if params[:board_id].to_i == board.id if params[:board_id].to_i == board.id
board board
else else
...@@ -55,8 +56,10 @@ module API ...@@ -55,8 +56,10 @@ module API
authorize!(:admin_list, user_project) authorize!(:admin_list, user_project)
list = ::Boards::Lists::CreateService.new(user_project, current_user, service = ::Boards::Lists::CreateService.new(user_project, current_user,
{ label_id: params[:label_id] }).execute { label_id: params[:label_id] })
list = service.execute(project_board)
if list.valid? if list.valid?
present list, with: Entities::List present list, with: Entities::List
...@@ -78,10 +81,10 @@ module API ...@@ -78,10 +81,10 @@ module API
authorize!(:admin_list, user_project) authorize!(:admin_list, user_project)
moved = ::Boards::Lists::MoveService.new(user_project, current_user, service = ::Boards::Lists::MoveService.new(user_project, current_user,
{ position: params[:position].to_i }).execute(list) { position: params[:position].to_i })
if moved if service.execute(list)
present list, with: Entities::List present list, with: Entities::List
else else
render_api_error!({ error: "List could not be moved!" }, 400) render_api_error!({ error: "List could not be moved!" }, 400)
...@@ -97,16 +100,16 @@ module API ...@@ -97,16 +100,16 @@ module API
# Example Request: # Example Request:
# DELETE /projects/:id/boards/:board_id/lists/:list_id # DELETE /projects/:id/boards/:board_id/lists/:list_id
delete "/lists/:list_id" do delete "/lists/:list_id" do
list = board_lists.find_by(id: params[:list_id])
authorize!(:admin_list, user_project) authorize!(:admin_list, user_project)
if list list = board_lists.find(params[:list_id])
destroyed_list = ::Boards::Lists::DestroyService.new(
user_project, current_user).execute(list) service = ::Boards::Lists::DestroyService.new(user_project, current_user)
present destroyed_list, with: Entities::List
if service.execute(list)
present list, with: Entities::List
else else
not_found!('List') render_api_error!({ error: 'List could not be deleted!' }, 400)
end end
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