Sha256: 466ade71711e1c4d0802ce57c05e788c8d5d0b691e02435a07fa1e946251f90b

Contents?: true

Size: 1.33 KB

Versions: 84

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    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 = Spree::Zone.
          accessible_by(current_ability).
          order('name ASC').
          ransack(params[:q]).
          result

        @zones = paginate(@zones)

        respond_with(@zones)
      end

      def show
        respond_with(zone)
      end

      def update
        authorize! :update, zone
        if zone.update(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, :show).find(params[:id])
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-3.2.5 app/controllers/spree/api/zones_controller.rb
solidus_api-3.2.4 app/controllers/spree/api/zones_controller.rb
solidus_api-3.2.3 app/controllers/spree/api/zones_controller.rb
solidus_api-3.1.8 app/controllers/spree/api/zones_controller.rb
solidus_api-3.0.8 app/controllers/spree/api/zones_controller.rb
solidus_api-3.2.2 app/controllers/spree/api/zones_controller.rb
solidus_api-3.2.1 app/controllers/spree/api/zones_controller.rb
solidus_api-3.2.0 app/controllers/spree/api/zones_controller.rb
solidus_api-3.2.0.alpha app/controllers/spree/api/zones_controller.rb
solidus_api-3.0.7 app/controllers/spree/api/zones_controller.rb
solidus_api-2.11.17 app/controllers/spree/api/zones_controller.rb
solidus_api-3.1.7 app/controllers/spree/api/zones_controller.rb
solidus_api-2.11.16 app/controllers/spree/api/zones_controller.rb
solidus_api-3.0.6 app/controllers/spree/api/zones_controller.rb
solidus_api-3.1.6 app/controllers/spree/api/zones_controller.rb
solidus_api-2.11.15 app/controllers/spree/api/zones_controller.rb
solidus_api-2.11.14 app/controllers/spree/api/zones_controller.rb
solidus_api-3.0.5 app/controllers/spree/api/zones_controller.rb
solidus_api-3.1.5 app/controllers/spree/api/zones_controller.rb
solidus_api-2.11.13 app/controllers/spree/api/zones_controller.rb