Sha256: a08fd33d4a5d713567c056a7b17fbb03ea9ac9e8355bc02ab10b7c9b43665649

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

  class AccountsController < ApplicationController
  def index
    @accounts = Account.all
  end

  def deposit_form
    @account = Account.find_by_name params[:id]
    @deposit = Account::DepositCommand.new
  end

  def deposit
    @account = Account.find_by_name params[:id]
    @deposit = @account.deposit params[:deposit]

    if @deposit.success?
      redirect_to root_path, notice: "Deposited #{@deposit.amount} to #{@account.name}'s account."
    else
      render "deposit_form"
    end
  end

  def withdraw_form
    @account = Account.find_by_name params[:id]
    @withdraw = Account::WithdrawCommand.new
  end

  def withdraw
    @account = Account.find_by_name params[:id]
    @withdraw = @account.withdraw params[:withdraw]

    if @withdraw.success?
      redirect_to root_path, notice: "Withdrew #{@withdraw.amount} from #{@account.name}'s account."
    else
      render "withdraw_form"
    end
  end

  def transfer_form
    @accounts = Account.all
    @transfer = Account::TransferCommand.new
  end

  def transfer
    @transfer = Account::TransferCommand.new(params[:transfer])

    if @transfer.call.success?
      redirect_to root_path, notice: "Transferred #{@transfer.amount} from #{@transfer.from.name}'s account to #{@transfer.to.name}'s account."
    else
      @accounts = Account.all
      render "transfer_form"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
command_model-2.1.1 examples/bank/app/controllers/accounts_controller.rb
command_model-2.1.0 examples/bank/app/controllers/accounts_controller.rb