Documentation ¶
Overview ¶
Package level documentation goes here!
Todo: - explain how the library works - architecture of the library
Index ¶
- Constants
- func Connect(database string) (*sql.DB, error)
- type Expense
- func (e *Expense) AddSimple(db meddler.DB, lender *User, debtor *User) (*Transaction, error)
- func (e *Expense) AddSplit(db meddler.DB, lender *User, debtors []*User) ([]*Transaction, error)
- func (e *Expense) Remove(db meddler.DB) error
- func (e *Expense) String() string
- func (e *Expense) Transactions(db meddler.DB) ([]*Transaction, error)
- type ExpenseType
- type Label
- type MoneyAmount
- type Transaction
- type User
Constants ¶
const ( DATE_FMT = "2006-01-02" TEST_DB = "/tmp/banktorrent.test.db" PROD_DB = "/Users/jason/Desktop/transactions.db" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Expense ¶
type Expense struct { Id int64 `meddler:"id,pk"` Amount int `meddler:"amount"` LabelId int64 `meddler:"label_id"` Comment string `meddler:"comment"` Date string `meddler:"date"` }
func CreateExpense ¶
func CreateExpense(db meddler.DB, amount *MoneyAmount, label *Label, comment string, date time.Time) (*Expense, error)
Creates the expense in the db and gives it an ID
func (*Expense) AddSimple ¶
Adds a single transaction. The entire expense amount is credited to the lender and charged to the debtor
func (*Expense) AddSplit ¶
Adds 1 transaction per debtor. The amount is split evenly between everyone (penny errors can occur). This type of transaction is useful even with just 2 people (a debtor and a lender) because it behaves differently than a SimpleExpense. Namely, it splits the expense.Amount evenly between everyone, including the lender, allowing for "shared expenses" to be added easily
func (*Expense) Remove ¶
Removes the expense by reversing all transactions associated with it, and deleting the expense from the db
func (*Expense) Transactions ¶
func (e *Expense) Transactions(db meddler.DB) ([]*Transaction, error)
type ExpenseType ¶
type ExpenseType int
const ( UNKNOWN_EXPENSE ExpenseType = iota SIMPLE_EXPENSE SPLIT_EXPENSE )
Currently supported expense types
func StringToExpenseType ¶
func StringToExpenseType(etype string) (ExpenseType, error)
func (ExpenseType) String ¶
func (e ExpenseType) String() string
type MoneyAmount ¶
func IntToMoney ¶
func IntToMoney(amount int) *MoneyAmount
func StringToMoney ¶
func StringToMoney(amount string) (*MoneyAmount, error)
func (*MoneyAmount) Int ¶
func (m *MoneyAmount) Int() int
Return the money amount as a regular int useful for saving to the db until I figure out how to use Meddler to do it
func (*MoneyAmount) String ¶
func (m *MoneyAmount) String() string
type Transaction ¶
type Transaction struct { Id int64 `meddler:"id,pk"` LenderId int64 `meddler:"lender_id"` DebtorId int64 `meddler:"debtor_id"` Amount int `meddler:"amount"` Date string `meddler:"date"` ExpenseId int64 `meddler:"expense_id"` }
func GetTransactionById ¶
func GetTransactionById(db meddler.DB, id int64) (*Transaction, error)
func (*Transaction) String ¶
func (t *Transaction) String() string