Sha256: 9362f167d88e2ee0cfac06739bcf925afbf3b7c0f21aed0d4f71c558ea78961c

Contents?: true

Size: 1.29 KB

Versions: 40

Compression:

Stored size: 1.29 KB

Contents

module Spree
  module Api
    class StockMovementsController < Spree::Api::BaseController
      before_filter :stock_location, except: [:update, :destroy]

      def index
        authorize! :read, StockMovement
        @stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
        respond_with(@stock_movements)
      end

      def show
        @stock_movement = scope.find(params[:id])
        respond_with(@stock_movement)
      end

      def create
        authorize! :create, StockMovement
        @stock_movement = scope.new(stock_movement_params)
        if @stock_movement.save
          respond_with(@stock_movement, status: 201, default_template: :show)
        else
          invalid_resource!(@stock_movement)
        end
      end

      private

      def stock_location
        render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
        @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
      end

      def scope
        @stock_location.stock_movements.accessible_by(current_ability, :read)
      end

      def stock_movement_params
        params.require(:stock_movement).permit(permitted_stock_movement_attributes)
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
spree_api-2.3.13 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.14 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.12 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.13 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.11 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.12 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.10 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.9 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.11 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.10 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.8 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.7 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.9 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.1.12 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.6 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.8 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.1.11 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.3.5 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.2.7 app/controllers/spree/api/stock_movements_controller.rb
spree_api-2.1.10 app/controllers/spree/api/stock_movements_controller.rb