Sha256: 67bb8c3ec3d73ecabce2e07f9144b1bb95455de2048f9298adb0c7d03f900105

Contents?: true

Size: 1.68 KB

Versions: 50

Compression:

Stored size: 1.68 KB

Contents

module Spree
  module Api
    module V1
      class TaxonomiesController < Spree::Api::BaseController
        def index
          respond_with(taxonomies)
        end

        def show
          respond_with(taxonomy)
        end

        # Because JSTree wants parameters in a *slightly* different format
        def jstree
          show
        end

        def new; end

        def create
          authorize! :create, Taxonomy
          @taxonomy = 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.
                        page(params[:page]).per(params[:per_page])
        end

        def taxonomy
          @taxonomy ||= Taxonomy.accessible_by(current_ability, :show).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
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
spree_api-4.0.9 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.1.15 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.7 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.6 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.5 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.1.14 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.0.8 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.4 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.3.1 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.1.13.1 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.0.7.1 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.3 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.2 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.1 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.0.7 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.0 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.0.rc5 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.0.rc4 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.2.0.rc3 app/controllers/spree/api/v1/taxonomies_controller.rb
spree_api-4.1.13 app/controllers/spree/api/v1/taxonomies_controller.rb