Sha256: 1b787f80be01609c7751e195c01df1869d9f33873384cfd3d362b8713949ed58

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # A command with all the business logic when creating a new participatory
    # process in the system.
    class CreateParticipatoryProcess < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(form)
        @form = form
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        create_participatory_process
        broadcast(:ok)
      end

      private

      attr_reader :form

      def create_participatory_process
        ParticipatoryProcess.create!(
          title: form.title,
          subtitle: form.subtitle,
          slug: form.slug,
          hashtag: form.hashtag,
          description: form.description,
          short_description: form.short_description,
          hero_image: form.hero_image,
          banner_image: form.banner_image,
          promoted: form.promoted,
          organization: form.current_organization
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
decidim-admin-0.0.1 app/commands/decidim/admin/create_participatory_process.rb
decidim-0.0.1 decidim-admin/app/commands/decidim/admin/create_participatory_process.rb