Sha256: 0dc55dcb10334e6a211cff4564dc4e3fa55c20b25356bb38ae92f09eda68ef00

Contents?: true

Size: 1.52 KB

Versions: 86

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    class StockLocationsController < Spree::Api::BaseController
      def index
        authorize! :index, StockLocation

        @stock_locations = StockLocation.
          accessible_by(current_ability).
          order('name ASC').
          ransack(params[:q]).
          result

        @stock_locations = paginate(@stock_locations)

        respond_with(@stock_locations)
      end

      def show
        respond_with(stock_location)
      end

      def create
        authorize! :create, StockLocation
        @stock_location = Spree::StockLocation.new(stock_location_params)
        if @stock_location.save
          respond_with(@stock_location, status: 201, default_template: :show)
        else
          invalid_resource!(@stock_location)
        end
      end

      def update
        authorize! :update, stock_location
        if stock_location.update(stock_location_params)
          respond_with(stock_location, status: 200, default_template: :show)
        else
          invalid_resource!(stock_location)
        end
      end

      def destroy
        authorize! :destroy, stock_location
        stock_location.destroy
        respond_with(stock_location, status: 204)
      end

      private

      def stock_location
        @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :show).find(params[:id])
      end

      def stock_location_params
        params.require(:stock_location).permit(permitted_stock_location_attributes)
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
solidus_api-3.1.5 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.13 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.0.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.1.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.12 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.0.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.1.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.1.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.1.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.1.0 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.11 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.0.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.10 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.0.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.0.0 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.9 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.8 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.7 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.11.6 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.0.0.rc2 app/controllers/spree/api/stock_locations_controller.rb