1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-12 23:09:03 +01:00
fab-manager/app/controllers/api/wallet_controller.rb

27 lines
654 B
Ruby
Raw Normal View History

2016-07-18 18:16:54 +02:00
class API::WalletController < API::ApiController
before_action :authenticate_user!
def by_user
@wallet = Wallet.find_by(user_id: params[:user_id])
authorize @wallet
2016-07-18 18:16:54 +02:00
render :show
end
2016-07-05 13:20:25 +02:00
def transactions
@wallet = Wallet.find(params[:id])
authorize @wallet
@wallet_transactions = @wallet.wallet_transactions.includes(:invoice, user: [:profile]).order(created_at: :desc)
2016-07-05 13:20:25 +02:00
end
def credit
@wallet = Wallet.find(params[:id])
authorize @wallet
service = WalletService.new(user: current_user, wallet: @wallet)
if service.credit(params[:amount].to_f)
render :show
else
head 422
end
end
2016-07-18 18:16:54 +02:00
end