Sha256: 6a114916258350ef2201663fc6fb5e0319935a60d9ea413acb3b4a6e2bc03698

Contents?: true

Size: 1.58 KB

Versions: 36

Compression:

Stored size: 1.58 KB

Contents

module Spree
  module Api
    module V2
      module Storefront
        class TaxonsController < ::Spree::Api::V2::BaseController
          include Spree::Api::V2::CollectionOptionsHelpers

          def index
            render_serialized_payload { serialize_collection(paginated_collection) }
          end

          def show
            render_serialized_payload { serialize_resource(resource) }
          end

          private

          def collection_serializer
            Spree::Api::Dependencies.storefront_taxon_serializer.constantize
          end

          def resource_serializer
            Spree::Api::Dependencies.storefront_taxon_serializer.constantize
          end

          def collection_finder
            Spree::Api::Dependencies.storefront_taxon_finder.constantize
          end

          def paginated_collection
            collection_paginator.new(collection, params).call
          end

          def collection
            collection_finder.new(scope: scope, params: params).execute
          end

          def resource
            scope.find_by(permalink: params[:id]) || scope.find(params[:id])
          end

          def scope
            Spree::Taxon.accessible_by(current_ability, :show).includes(scope_includes)
          end

          def scope_includes
            node_includes = %i[icon products parent taxonomy]

            {
              parent: node_includes,
              children: node_includes,
              taxonomy: [root: node_includes],
              products: [],
              icon: []
            }
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
spree_api-4.0.9 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.15 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.14 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.0.8 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.13.1 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.0.7.1 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.0.7 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.13 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.0.6 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.0.5 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.12 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.0.4 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.11 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.10 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.2.0.beta app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.9 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.8 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.7 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.6 app/controllers/spree/api/v2/storefront/taxons_controller.rb
spree_api-4.1.5 app/controllers/spree/api/v2/storefront/taxons_controller.rb