<commit_before># 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
        authorize_action! "vote"

        AddLineItem.call(current_order, project, current_user) do
          on(:ok) do |order|
            self.current_order = order
            render "update_budget"
          end

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

      def destroy
        RemoveLineItem.call(current_order, project) do
          on(:ok) do |_order|
            render "update_budget"
          end

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

      private

      def project
        @project ||= Project.where(id: params[:project_id], feature: current_feature).first
      end
    end
  end
end<commit_msg>Respond with html when adding or removing projects (#1227)<commit_after># 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
        authorize_action! "vote"

        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: 422
            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: 422
            end
          end
        end
      end

      private

      def project
        @project ||= Project.where(id: params[:project_id], feature: current_feature).first
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06407606448945845, 'fraction_numerical': 0.006614303431169905, 'mean_word_length': 1.8304093567251463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7152283', 'n_tokens_mistral': 656, 'n_tokens_neox': 620, 'n_words': 195}