Documentation
¶
Index ¶
- Variables
- func RunCommand(atm *ATM, command string) error
- type ATM
- func (atm *ATM) Authorize(accountID int, accountPIN string) bool
- func (atm *ATM) Balance(accountID int) (float64, error)
- func (atm *ATM) Deposit(accountID int, amount float64) error
- func (atm *ATM) History(accountID int) []Transaction
- func (atm *ATM) Logout() error
- func (atm *ATM) Withdraw(accountID int, amount int) (bool, error)
- type Account
- type AccountDB
- type Command
- type CommandRun
- type IATM
- type IAccountDB
- type ICommand
- type ISession
- type ITransactionDB
- type Session
- type Transaction
- type TransactionDB
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthorizationUnsuccessful = errors.New("Authorization failed.") ErrAuthorizationRequired = errors.New("Authorization required.") )
authorize errors
var ( ErrWithdrawATMInsufficientFunds = errors.New("Unable to dispense full amount requested at this time.") ErrWithdrawATMNoFunds = errors.New("Unable to process your withdrawal at this time.") ErrWithdrawAccountOverdrawn = errors.New("Your account is overdrawn! You may not make withdrawals at this time.") ErrWithdrawAmountNoMultipleOf20 = errors.New("Unable to process since amount is not a multiple of 20.") )
withdraw errors
var ( ErrAccountNotFound = errors.New("Account could not be found in database.") ErrAccountIDNotInteger = errors.New("Account ID is not an integer") ErrAccountBalanceNotFloat = errors.New("Balance is not a float") )
account db error
var ( ErrTransactionAccountIDNotInteger = errors.New("Account ID is not an integer") ErrTransactionDateTimeNotInteger = errors.New("Datetime is not an integer") ErrTransactionAmounteNotFloat = errors.New("Amount is not a float") ErrTransactionBalanceNotFloat = errors.New("Balance is not a float") )
transaction db error
var ( ErrSessionNoActiveSession = errors.New("No active session found. Authorization required.") ErrSessionInvalidAccountID = errors.New("Invalid account ID for session.") ErrSessionTimedOut = errors.New("Session has timed out.") )
session error
var ( ErrConsoleInvalidCommand = errors.New("Invalid command. e.g. ") ErrConsoleAuthorizationFailed = errors.New("Authorization failed.") ErrConsoleInvalidAmount = errors.New("Amount is not a valid") )
console error
var (
ErrLogoutNoActiveSession = errors.New("No account is currently authorized.")
)
logout errors
Functions ¶
func RunCommand ¶
RunCommand will execute the command given the command string If an invalid command is used then the help message is displayed
Types ¶
type ATM ¶
type ATM struct {
AccountDB IAccountDB
TransactionDB ITransactionDB
ATMBalance float64
Session *Session
}
func (*ATM) Authorize ¶
Authorize authorizes the accountID with the accountPIM If pin and accountID is correct then a session is created that should expire in 2 mins
func (*ATM) Balance ¶
Balance returns the current balance An error is returned if no active session or account balance could not be found in DB
func (*ATM) Deposit ¶
Deposit deposits a specific amount to the account and updates the AccountDB and TransactionDB An error is returned if no actives session or failure to interface with DBs
func (*ATM) History ¶
func (atm *ATM) History(accountID int) []Transaction
History returns the history of a specific account If error occurs an empty list is returned
func (*ATM) Logout ¶
Logout logouts of the current session An error is returned if no active session could be closed
func (*ATM) Withdraw ¶
Withdraw withraws a specific amount from an account and updates value in AccountsDB and TransactionDB Withdrawl will fail if session not active or session timed out, atm balance is 0, withdrawl amount is more than atm balance, account current balance is negative, If withdrawl amount is more than account's balance then overdrawn boolean is true
type AccountDB ¶
type AccountDB struct {
DBFile string
}
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func DefaultCommands ¶
func DefaultCommands() []Command
DefaultCommands returns all of the commands valid in the console
type CommandRun ¶
type IAccountDB ¶
type ITransactionDB ¶
type ITransactionDB interface {
// return all transactions for a given account
Get(int) ([]Transaction, error)
// add a transaction return error if failure to add transaction
Set(Transaction) error
}
type Session ¶
func (*Session) Authorize ¶
Authorize will set the LastActivity time to now and the AccountID of the session
type Transaction ¶
type TransactionDB ¶
type TransactionDB struct {
DBFile string
}
func (TransactionDB) Get ¶
func (t TransactionDB) Get(accountID int) ([]Transaction, error)
Get retrieves a list of transactions for a given accountID from a CSV file An error is returned on failure to read the CSV file
func (TransactionDB) Set ¶
func (t TransactionDB) Set(transaction Transaction) error
Set appends a transaction to the transactions CSV file An error is returned on failure to read or write the CSV file