PageRenderTime 1357ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/api/app/controllers/spree/api/v1/return_authorizations_controller.rb

http://github.com/spree/spree
Ruby | 70 lines | 61 code | 9 blank | 0 comment | 3 complexity | 710565f2a866564712cec7888c612b00 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Api
  3. module V1
  4. class ReturnAuthorizationsController < Spree::Api::BaseController
  5. def create
  6. authorize! :create, ReturnAuthorization
  7. @return_authorization = order.return_authorizations.build(return_authorization_params)
  8. if @return_authorization.save
  9. respond_with(@return_authorization, status: 201, default_template: :show)
  10. else
  11. invalid_resource!(@return_authorization)
  12. end
  13. end
  14. def destroy
  15. @return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
  16. @return_authorization.destroy
  17. respond_with(@return_authorization, status: 204)
  18. end
  19. def index
  20. authorize! :admin, ReturnAuthorization
  21. @return_authorizations = order.return_authorizations.accessible_by(current_ability).
  22. ransack(params[:q]).result.
  23. page(params[:page]).per(params[:per_page])
  24. respond_with(@return_authorizations)
  25. end
  26. def new
  27. authorize! :admin, ReturnAuthorization
  28. end
  29. def show
  30. authorize! :admin, ReturnAuthorization
  31. @return_authorization = order.return_authorizations.accessible_by(current_ability, :show).find(params[:id])
  32. respond_with(@return_authorization)
  33. end
  34. def update
  35. @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
  36. if @return_authorization.update(return_authorization_params)
  37. respond_with(@return_authorization, default_template: :show)
  38. else
  39. invalid_resource!(@return_authorization)
  40. end
  41. end
  42. def cancel
  43. @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
  44. if @return_authorization.cancel
  45. respond_with @return_authorization, default_template: :show
  46. else
  47. invalid_resource!(@return_authorization)
  48. end
  49. end
  50. private
  51. def order
  52. @order ||= Spree::Order.find_by!(number: order_id)
  53. authorize! :show, @order
  54. end
  55. def return_authorization_params
  56. params.require(:return_authorization).permit(permitted_return_authorization_attributes)
  57. end
  58. end
  59. end
  60. end
  61. end