Sha256: 357fd127d18605fa3f78c72071851ceaeb55dfad3900d8acced7993745640111

Contents?: true

Size: 1.5 KB

Versions: 84

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    class OptionTypesController < Spree::Api::BaseController
      def index
        if params[:ids]
          @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability).where(id: params[:ids].split(','))
        else
          @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability).load.ransack(params[:q]).result
        end
        respond_with(@option_types)
      end

      def show
        @option_type = Spree::OptionType.accessible_by(current_ability, :show).find(params[:id])
        respond_with(@option_type)
      end

      def create
        authorize! :create, Spree::OptionType
        @option_type = Spree::OptionType.new(option_type_params)
        if @option_type.save
          render :show, status: 201
        else
          invalid_resource!(@option_type)
        end
      end

      def update
        @option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
        if @option_type.update(option_type_params)
          render :show
        else
          invalid_resource!(@option_type)
        end
      end

      def destroy
        @option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
        @option_type.destroy
        render plain: nil, status: 204
      end

      private

      def option_type_params
        params.require(:option_type).permit(permitted_option_type_attributes)
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-4.1.1 app/controllers/spree/api/option_types_controller.rb
solidus_api-4.0.2 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.4.4 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.3.4 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.2.9 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.2.8 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.3.3 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.4.3 app/controllers/spree/api/option_types_controller.rb
solidus_api-4.0.1 app/controllers/spree/api/option_types_controller.rb
solidus_api-4.1.0 app/controllers/spree/api/option_types_controller.rb
solidus_api-4.0.0 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.4.2 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.2.7 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.3.2 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.4.1 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.4.0 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.3.1 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.2.6 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.1.9 app/controllers/spree/api/option_types_controller.rb
solidus_api-3.3.0 app/controllers/spree/api/option_types_controller.rb