Sha256: f0f407e8d5b531f7a3ca1470b8857715d35ef3dfd3d78d14644e04ae0f77f73c

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

require 'stormwatch/workflows/base'

module Stormwatch
  module Workflows
    class CreateBox < Base
      include Requirements[
        'storage.boards',
        'storage.boxes'
      ]

      def call(payload:)
        payload = Payload.new(payload)

        board = boards.find_board(payload.uuid)

        if board.nil?
          broadcast(:not_found)
          return
        end

        unless box = boxes.create_box(board.id, payload.content)
          broadcast(:not_created)
          return
        end

        broadcast(
          :success, 
          {
            uuid: box.uuid,
            content: box.content,
            board_uuid: board.uuid
          }
        )
      end

      class Payload < Base::Payload
        attribute :uuid, Types::String
        attribute :content, Types::String
      end

    end

    Registry.register(
      'create_box',
      -> {CreateBox.new}
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stormwatch-workflows-0.1.3 lib/stormwatch/workflows/create_box.rb