Sha256: af2a0d9fb838223e4decb5d4a5f8377d04573edefe81634d7e73415b7b2801ac

Contents?: true

Size: 1.56 KB

Versions: 66

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    class TaxonomiesController < Spree::Api::BaseController
      def index
        @taxonomies = paginate(taxonomies)
        respond_with(@taxonomies)
      end

      def new
      end

      def show
        respond_with(taxonomy)
      end

      def create
        authorize! :create, Taxonomy
        @taxonomy = Spree::Taxonomy.new(taxonomy_params)
        if @taxonomy.save
          respond_with(@taxonomy, status: 201, default_template: :show)
        else
          invalid_resource!(@taxonomy)
        end
      end

      def update
        authorize! :update, taxonomy
        if taxonomy.update(taxonomy_params)
          respond_with(taxonomy, status: 200, default_template: :show)
        else
          invalid_resource!(taxonomy)
        end
      end

      def destroy
        authorize! :destroy, taxonomy
        taxonomy.destroy
        respond_with(taxonomy, status: 204)
      end

      private

      def taxonomies
        @taxonomies = Taxonomy.
          accessible_by(current_ability).
          order('name').
          includes(root: :children).
          ransack(params[:q]).
          result
      end

      def taxonomy
        @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :show).
          includes(root: :children).
          find(params[:id])
      end

      def taxonomy_params
        if params[:taxonomy] && !params[:taxonomy].empty?
          params.require(:taxonomy).permit(permitted_taxonomy_attributes)
        else
          {}
        end
      end
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
solidus_api-4.4.1 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.4.0 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.3.4 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.2.4 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.1.5 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.3.3 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.3.2 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.1.4 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.3.1 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.3.0 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.2.3 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.1.3 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.0.4 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-3.4.6 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.0.3 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.1.2 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.2.2 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-3.4.5 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.2.1 app/controllers/spree/api/taxonomies_controller.rb
solidus_api-4.2.0 app/controllers/spree/api/taxonomies_controller.rb