app/controllers/trade/admin/refunds_controller.rb in rails_trade-0.0.2 vs app/controllers/trade/admin/refunds_controller.rb in rails_trade-0.0.3
- old
+ new
@@ -1,57 +1,68 @@
-class Trade::Admin::RefundsController < Trade::Admin::BaseController
- before_action :set_refund, only: [:show, :edit, :update, :confirm, :deny, :destroy]
+module Trade
+ class Admin::RefundsController < Admin::BaseController
+ before_action :set_refund, only: [:show, :edit, :update, :confirm, :deny, :destroy]
- def index
- @refunds = Refund.includes(:order, :payment).default_where(params.permit(:order_id, :payment_id)).page(params[:page])
- end
+ def index
+ q_params = {}
+ q_params.merge! default_params
+ q_params.merge! params.permit(:order_id, :payment_id)
- def show
- end
+ @refunds = Refund.includes(:order, :payment).default_where(q_params).page(params[:page])
+ end
- def new
- @refund = @payment.refunds.build
- end
+ def new
+ @refund = @payment.refunds.build
+ end
- def edit
- end
+ def create
+ @refund = Refund.new(refund_params)
- def create
- @refund = Refund.new(refund_params)
+ unless @refund.save
+ render :new, locals: { model: @refund }, status: :unprocessable_entity
+ end
+ end
- unless @refund.save
- render :new, locals: { model: @refund }, status: :unprocessable_entity
+ def show
end
- end
- def update
- @refund.assign_attributes(refund_params)
+ def edit
+ end
- unless @refund.save
- render :new, locals: { model: @refund }, status: :unprocessable_entity
+ def update
+ @refund.assign_attributes(refund_params)
+
+ unless @refund.save
+ render :new, locals: { model: @refund }, status: :unprocessable_entity
+ end
end
- end
- def confirm
- @refund.do_refund(operator_id: current_user.id, operator_type: current_user.class.name)
- redirect_to admin_refunds_url(order_id: @refund.order_id)
- end
+ def confirm
+ @refund.do_refund
+ @refund.operator = current_member
+ @refund.refunded_at = Time.current
- def deny
- @refund.deny_refund(operator_id: current_user.id, operator_type: current_user.class.name)
- redirect_to admin_refunds_url(order_id: @refund.order_id)
- end
+ @refund.save
+ end
- def destroy
- @refund.destroy
- end
+ def deny
+ @refund.state = 'denied'
+ @refund.operator = current_member
- private
- def set_refund
- @refund = Refund.find(params[:id])
- end
+ @refund.save
+ end
- def refund_params
- params.fetch(:refund, {})
- end
+ def destroy
+ @refund.destroy
+ end
+ private
+ def set_refund
+ @refund = Refund.find(params[:id])
+ end
+
+ def refund_params
+ params.fetch(:refund, {})
+ end
+
+ end
end