Sha256: f2d4d63bfc959dcebd7a40026da55b33d6963af6f6b11d7ed024527881eed1a8

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

module Spree
  module Api
    module V1
      class VendorsController < Spree::Api::V1::BaseController
        def index
          @vendors = if params[:ids].present?
                       scope.where(id: params[:ids].split(','))
                     else
                       scope.load.ransack(
                         params[:q]
                       ).result
                     end
          respond_with(@vendors)
        end

        def show
          @vendor = scope.find(params[:id])
          authorize! :show, @vendor
          respond_with(@vendor)
        end

        def create
          authorize! :create, Spree::Vendor
          @vendor = Spree::Vendor.new(vendor_params)
          if @vendor.save
            render :show, status: 201
          else
            invalid_resource!(@vendor)
          end
        end

        def update
          @vendor = scope.find(params[:id])
          authorize! :update, @vendor
          if @vendor.update(vendor_params)
            render :show
          else
            invalid_resource!(@vendor)
          end
        end

        def destroy
          @vendor = scope.find(params[:id])
          authorize! :destroy, @vendor
          @vendor.destroy
          render plain: nil, status: 204
        end

        private

        def scope
          Spree::Vendor.accessible_by(current_ability)
        end

        def vendor_params
          params.require(:vendor).permit(Spree::PermittedAttributes.vendor_attributes)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_multi_vendor-2.5.0 app/controllers/spree/api/v1/vendors_controller.rb
spree_multi_vendor-2.4.1 app/controllers/spree/api/v1/vendors_controller.rb
spree_multi_vendor-2.4.0 app/controllers/spree/api/v1/vendors_controller.rb