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