create_service.rb 430 Bytes
Newer Older
1
module Boards
Felipe's avatar
Felipe committed
2
  class CreateService < Boards::BaseService
3
    def execute
4
      create_board! if can_create_board?
5 6 7 8
    end

    private

9
    def can_create_board?
Felipe's avatar
Felipe committed
10
      parent.boards.size == 0
11 12
    end

13
    def create_board!
Felipe's avatar
Felipe committed
14
      board = parent.boards.create(params)
15 16 17 18 19

      if board.persisted?
        board.lists.create(list_type: :backlog)
        board.lists.create(list_type: :closed)
      end
20 21

      board
22
    end
23 24
  end
end