Sha256: 0dc55dcb10334e6a211cff4564dc4e3fa55c20b25356bb38ae92f09eda68ef00

Contents?: true

Size: 1.52 KB

Versions: 84

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

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-4.4.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.4.0 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.3.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.2.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.1.5 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.3.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.3.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.1.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.3.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.3.0 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.2.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.1.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.0.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.4.6 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.0.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.1.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.2.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-3.4.5 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.2.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-4.2.0 app/controllers/spree/api/stock_locations_controller.rb