Sha256: 04e3295aaf8843a790568f1a75d574e0d26c06b9ef402f09d910f2641b17d6a3

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module Spree
  module Api
    module V1
      class TaxonsController < Spree::Api::V1::BaseController
        def index
          @taxons = taxonomy.root.children
        end

        def show
          @taxon = taxon
        end

        def create
          authorize! :create, Taxon
          @taxon = Taxon.new(params[:taxon])
          if @taxon.save
            render :show, :status => 201
          else
            invalid_resource!(@taxon)
          end
        end

        def update
          authorize! :update, Taxon
          if taxon.update_attributes(params[:taxon])
            render :show, :status => 200
          else
            invalid_resource!(taxon)
          end
        end

        def destroy
          authorize! :delete, Taxon
          taxon.destroy
          render :text => nil, :status => 204
        end

        private

        def taxonomy
          @taxonomy ||= Taxonomy.find(params[:taxonomy_id])
        end

        def taxon
          @taxon ||= taxonomy.taxons.find(params[:id])
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_api-1.2.5 app/controllers/spree/api/v1/taxons_controller.rb
spree_api-1.2.4 app/controllers/spree/api/v1/taxons_controller.rb
spree_api-1.2.3 app/controllers/spree/api/v1/taxons_controller.rb
spree_api-1.2.2 app/controllers/spree/api/v1/taxons_controller.rb