2016-09-13 17:45:13 +05:30
|
|
|
module Boards
|
2016-11-03 12:29:30 +05:30
|
|
|
class CreateService < BaseService
|
2016-09-13 17:45:13 +05:30
|
|
|
def execute
|
2017-09-10 17:25:29 +05:30
|
|
|
create_board! if can_create_board?
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def can_create_board?
|
|
|
|
project.boards.size == 0
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def create_board!
|
2017-09-10 17:25:29 +05:30
|
|
|
board = project.boards.create(params)
|
|
|
|
|
|
|
|
if board.persisted?
|
|
|
|
board.lists.create(list_type: :backlog)
|
|
|
|
board.lists.create(list_type: :closed)
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
board
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|