Sha256: c69c7e3b7b6b227d3237ecff9b936013e4eaae917f7a79142868bb375b72b4b0

Contents?: true

Size: 1.54 KB

Versions: 44

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

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

        @stock_locations = StockLocation.
          accessible_by(current_ability, :read).
          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_attributes(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, :read).find(params[:id])
      end

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

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
solidus_api-2.9.6 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.8.6 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.5 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.6.6 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.7.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.8.5 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.7.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.6.5 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.0 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.9.0.rc.1 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.8.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.8.3 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.7.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.6.4 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.8.2 app/controllers/spree/api/stock_locations_controller.rb
solidus_api-2.8.1 app/controllers/spree/api/stock_locations_controller.rb