Sha256: 9849960032faed3f5a7c6ac1ef43fecb522dcbff0195e18dd4d3113ec6a75f88

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 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

4 entries across 4 versions & 2 rubygems

Version Path
spree_api-1.3.1 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-1.3.0 app/controllers/spree/api/return_authorizations_controller.rb
spree_api-1.3.0.rc2 app/controllers/spree/api/return_authorizations_controller.rb
dup_spree_api-1.3.0.rc1 app/controllers/spree/api/return_authorizations_controller.rb