Sha256: 1853a27ebcafedff3b55524b53765f2f598faab6fa96d0c9872e15d42ed52e98

Contents?: true

Size: 1.38 KB

Versions: 39

Compression:

Stored size: 1.38 KB

Contents

module Spree
  module Api
    module V1
      class ZonesController < Spree::Api::BaseController
        def create
          authorize! :create, Zone
          @zone = Spree::Zone.new(zone_params)
          if @zone.save
            respond_with(@zone, status: 201, default_template: :show)
          else
            invalid_resource!(@zone)
          end
        end

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

        def index
          @zones = Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
          respond_with(@zones)
        end

        def show
          respond_with(zone)
        end

        def update
          authorize! :update, zone
          if zone.update_attributes(zone_params)
            respond_with(zone, status: 200, default_template: :show)
          else
            invalid_resource!(zone)
          end
        end

        private

        def zone_params
          attrs = params.require(:zone).permit!
          if attrs[:zone_members]
            attrs[:zone_members_attributes] = attrs.delete(:zone_members)
          end
          attrs
        end

        def zone
          @zone ||= Spree::Zone.accessible_by(current_ability, :read).find(params[:id])
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
spree_api-3.7.14.1 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.14 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.13 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.12 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.11 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.4.6 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.10 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.9 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.8 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.7 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.6 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.5 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.4 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.3 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.2 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.1 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.0 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.0.rc3 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.0.rc2 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.7.0.rc1 app/controllers/spree/api/v1/zones_controller.rb