Sha256: 0ad8c724403f06c53cc894814b418d2c3c87b90f95b2e49ec0c03bb2c9beacb6

Contents?: true

Size: 1.27 KB

Versions: 17

Compression:

Stored size: 1.27 KB

Contents

module Spree
  module Api
    class ZonesController < Spree::Api::BaseController
      def create
        authorize! :create, Zone
        @zone = 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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
solidus_api-2.0.3 app/controllers/spree/api/zones_controller.rb
solidus_api-1.4.2 app/controllers/spree/api/zones_controller.rb
solidus_api-1.3.2 app/controllers/spree/api/zones_controller.rb
solidus_api-2.0.2 app/controllers/spree/api/zones_controller.rb
solidus_api-1.4.1 app/controllers/spree/api/zones_controller.rb
solidus_api-2.0.1 app/controllers/spree/api/zones_controller.rb
solidus_api-2.0.0 app/controllers/spree/api/zones_controller.rb
solidus_api-1.4.0 app/controllers/spree/api/zones_controller.rb
solidus_api-2.0.0.rc1 app/controllers/spree/api/zones_controller.rb
solidus_api-1.4.0.rc1 app/controllers/spree/api/zones_controller.rb
solidus_api-2.0.0.beta1 app/controllers/spree/api/zones_controller.rb
solidus_api-1.4.0.beta1 app/controllers/spree/api/zones_controller.rb
solidus_api-1.3.1 app/controllers/spree/api/zones_controller.rb
solidus_api-1.3.0 app/controllers/spree/api/zones_controller.rb
solidus_api-1.3.0.rc2 app/controllers/spree/api/zones_controller.rb
solidus_api-1.3.0.rc1 app/controllers/spree/api/zones_controller.rb
solidus_api-1.3.0.beta1 app/controllers/spree/api/zones_controller.rb