Sha256: 57ce87f5d73cd36cc52ef0242ddf8c338b060bf2e2998deb3da1cb0ab9a6779a

Contents?: true

Size: 1.37 KB

Versions: 61

Compression:

Stored size: 1.37 KB

Contents

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

        def index
          authorize! :index, 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/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
          @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id])
        end

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

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

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spree_api-4.0.9 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.1.15 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.2.7 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.3 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.4.1 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.2.6 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.2 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.4.0 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.4.0.rc2 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.1 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.4.0.rc1 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.0 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.0.rc3 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.0.rc2 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.3.0.rc1 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.2.5 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.1.14 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.0.8 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.2.4 app/controllers/spree/api/v1/stock_movements_controller.rb
spree_api-4.2.3.1 app/controllers/spree/api/v1/stock_movements_controller.rb