Sha256: 1b04959914c77719461882c3c16534b63403eb580e5397fe3951affad6f5033d

Contents?: true

Size: 1.27 KB

Versions: 84

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    class StoresController < Spree::Api::BaseController
      before_action :get_store, except: [:index, :create]

      def index
        authorize! :index, Store
        @stores = Spree::Store.accessible_by(current_ability).all
        respond_with(@stores)
      end

      def create
        authorize! :create, Store
        @store = Spree::Store.new(store_params)
        @store.code = params[:store][:code]
        if @store.save
          respond_with(@store, status: 201, default_template: :show)
        else
          invalid_resource!(@store)
        end
      end

      def update
        authorize! :update, @store
        if @store.update(store_params)
          respond_with(@store, status: 200, default_template: :show)
        else
          invalid_resource!(@store)
        end
      end

      def show
        authorize! :show, @store
        respond_with(@store)
      end

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

      private

      def get_store
        @store = Spree::Store.find(params[:id])
      end

      def store_params
        params.require(:store).permit(permitted_store_attributes)
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-4.1.1 app/controllers/spree/api/stores_controller.rb
solidus_api-4.0.2 app/controllers/spree/api/stores_controller.rb
solidus_api-3.4.4 app/controllers/spree/api/stores_controller.rb
solidus_api-3.3.4 app/controllers/spree/api/stores_controller.rb
solidus_api-3.2.9 app/controllers/spree/api/stores_controller.rb
solidus_api-3.2.8 app/controllers/spree/api/stores_controller.rb
solidus_api-3.3.3 app/controllers/spree/api/stores_controller.rb
solidus_api-3.4.3 app/controllers/spree/api/stores_controller.rb
solidus_api-4.0.1 app/controllers/spree/api/stores_controller.rb
solidus_api-4.1.0 app/controllers/spree/api/stores_controller.rb
solidus_api-4.0.0 app/controllers/spree/api/stores_controller.rb
solidus_api-3.4.2 app/controllers/spree/api/stores_controller.rb
solidus_api-3.2.7 app/controllers/spree/api/stores_controller.rb
solidus_api-3.3.2 app/controllers/spree/api/stores_controller.rb
solidus_api-3.4.1 app/controllers/spree/api/stores_controller.rb
solidus_api-3.4.0 app/controllers/spree/api/stores_controller.rb
solidus_api-3.3.1 app/controllers/spree/api/stores_controller.rb
solidus_api-3.2.6 app/controllers/spree/api/stores_controller.rb
solidus_api-3.1.9 app/controllers/spree/api/stores_controller.rb
solidus_api-3.3.0 app/controllers/spree/api/stores_controller.rb