2018-07-16 16:31:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-27 20:41:19 +00:00
|
|
|
module Boards
|
2017-08-28 21:56:49 +00:00
|
|
|
class CreateService < Boards::BaseService
|
2016-07-27 20:41:19 +00:00
|
|
|
def execute
|
2017-07-07 09:50:01 +00:00
|
|
|
create_board! if can_create_board?
|
2016-07-27 20:41:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-07-07 09:50:01 +00:00
|
|
|
def can_create_board?
|
2017-08-28 21:56:49 +00:00
|
|
|
parent.boards.size == 0
|
2017-07-07 09:50:01 +00:00
|
|
|
end
|
|
|
|
|
2016-07-28 04:36:38 +00:00
|
|
|
def create_board!
|
2017-08-28 21:56:49 +00:00
|
|
|
board = parent.boards.create(params)
|
2017-07-07 09:50:01 +00:00
|
|
|
|
|
|
|
if board.persisted?
|
|
|
|
board.lists.create(list_type: :backlog)
|
|
|
|
board.lists.create(list_type: :closed)
|
|
|
|
end
|
2016-10-06 19:20:21 +00:00
|
|
|
|
|
|
|
board
|
2016-07-28 04:36:38 +00:00
|
|
|
end
|
2016-07-27 20:41:19 +00:00
|
|
|
end
|
|
|
|
end
|