Sha256: e3e36053982b0ee7da5a33e7b2642bcfe74cc847998fade8603971b7a8ac3c79

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # Exposes the line items resource so users can create and remove from orders.
    class LineItemsController < Decidim::Budgets::ApplicationController
      include NeedsCurrentOrder

      helper_method :project

      def create
        enforce_permission_to :vote, :project, project: project

        respond_to do |format|
          AddLineItem.call(current_order, project, current_user) do
            on(:ok) do |order|
              self.current_order = order
              format.html { redirect_to :back }
              format.js { render "update_budget" }
            end

            on(:invalid) do
              render nothing: true, status: :unprocessable_entity
            end
          end
        end
      end

      def destroy
        respond_to do |format|
          RemoveLineItem.call(current_order, project) do
            on(:ok) do |_order|
              format.html { redirect_to :back }
              format.js { render "update_budget" }
            end

            on(:invalid) do
              render nothing: true, status: :unprocessable_entity
            end
          end
        end
      end

      private

      def project
        @project ||= Project.find_by(id: params[:project_id], component: current_component)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-budgets-0.21.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.20.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.20.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.19.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.19.0 app/controllers/decidim/budgets/line_items_controller.rb