Sha256: 3c4a83dd732f51b616d04cdf8f563245fe872403522d0ae33ad5dcd7ca3d33d2

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

module Spree
  module Api
    class ZonesController < Spree::Api::BaseController

      def create
        authorize! :create, Spree::Zone
        @zone = Spree::Zone.new(map_nested_attributes_keys(Spree::Zone, 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 = Spree::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(map_nested_attributes_keys(Spree::Zone, zone_params))
          respond_with(zone, :status => 200, :default_template => :show)
        else
          invalid_resource!(zone)
        end
      end

      private
      def zone_params
        params.require(:zone).permit!
      end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_api-3.0.10 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.9 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.8 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.7 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.6.1 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.6 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.5 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.4 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.3 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.2 app/controllers/spree/api/zones_controller.rb
spree_api-3.0.1 app/controllers/spree/api/zones_controller.rb