Sha256: 57e1f63df430a1839e22c290de723bf294f5222aa9fa17594a84407c12a919da

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 KB

Contents

module Spree
  module Api
    class ReturnAuthorizationsController < Spree::Api::BaseController
      respond_to :json

      before_filter :authorize_admin!

      def index
        @return_authorizations = order.return_authorizations.
                                 ransack(params[:q]).result.
                                 page(params[:page]).per(params[:per_page])
        respond_with(@return_authorizations)
      end

      def show
        @return_authorization = order.return_authorizations.find(params[:id])
        respond_with(@return_authorization)
      end

      def create
        @return_authorization = order.return_authorizations.build(params[:return_authorization], :as => :api)
        if @return_authorization.save
          respond_with(@return_authorization, :status => 201, :default_template => :show)
        else
          invalid_resource!(@return_authorization)
        end
      end

      def update
        @return_authorization = order.return_authorizations.find(params[:id])
        if @return_authorization.update_attributes(params[:return_authorization])
          respond_with(@return_authorization, :default_template => :show)
        else
          invalid_resource!(@return_authorization)
        end
      end

      def destroy
        @return_authorization = order.return_authorizations.find(params[:id])
        @return_authorization.destroy
        respond_with(@return_authorization, :status => 204)
      end

      private

      def order
        @order ||= Order.find_by_number!(params[:order_id])
      end

      def authorize_admin!
        authorize! :manage, Spree::ReturnAuthorization
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_api-1.3.5 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-1.3.4 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-2.0.3 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-1.3.3 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-2.0.2 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-2.0.1 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-2.0.0 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-2.0.0.rc1 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-1.3.2 app/controllers/spree/api/return_authorizations_controller.rb