Sha256: 0bd45e53e33265a9fe50aa479cd87d90fb62e2cba5fb42e5a950428ac2222c1f

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

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

        def create
          authorize! :create, Zone
          @zone = 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 = 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
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spree_api-3.2.9 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.8 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.7 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.6 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.5 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.4 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.3 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.2 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.1 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.0 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.0.rc3 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.0.rc2 app/controllers/spree/api/v1/zones_controller.rb
spree_api-3.2.0.rc1 app/controllers/spree/api/v1/zones_controller.rb