2016-09-13 17:45:13 +05:30
|
|
|
module Boards
|
|
|
|
module Lists
|
2016-11-03 12:29:30 +05:30
|
|
|
class CreateService < BaseService
|
|
|
|
def execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
List.transaction do
|
2016-11-03 12:29:30 +05:30
|
|
|
label = available_labels.find(params[:label_id])
|
|
|
|
position = next_position(board)
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
create_list(board, label, position)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def available_labels
|
|
|
|
LabelsFinder.new(current_user, project_id: project.id).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_position(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
max_position = board.lists.movable.maximum(:position)
|
|
|
|
max_position.nil? ? 0 : max_position.succ
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def create_list(board, label, position)
|
2016-09-29 09:46:39 +05:30
|
|
|
board.lists.create(label: label, list_type: :label, position: position)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|