banktorrent

package module
v0.0.0-...-067c6e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2013 License: MIT Imports: 9 Imported by: 0

README

BankTorrent

BankTorrent is a distributed debt and payment tracking system. It allows groups of people to keep track of shared expenses and how much they owe each other.

Author: Jason D'Souza

Todo

  • Write ability
    • remove users/ labels
      • only if there are no expenses/ transactions/ associated with them
      • cant remove if it would leave db in inconsistent state
    • make writing transactional
      • replace sql.Dx with sql.Tx
  • Meddler
    • use the MoneyAmount type instead of ints
    • change expense and transaction structs to use MoneyAmount
    • make a meddler that converts from the int to MoneyAmount
  • CLI
    • ability to backup db
    • remove expenses
    • get list of expenses
    • add labels
    • add users
    • get statistics
      • upcoming bills
      • potentially missing transactions
    • predictive user input
      • best guess based on input?
    • tests
  • web frontend
    • graphs
      • visualization of transaction history
      • breakdown by label
  • Tests
    • test coverage of all methods/ functions
  • Integrate terminal prettying

Workflow

  • easily add split/ simple transactions from command line
    • specify user/ label by name
    • enter amount in dollars and cents
  • visual reassurance that the math works out
    • show users balance before and after
  • easily correct a mistake
    • edit recently added expense?

Documentation

Overview

Package level documentation goes here!

Todo: - explain how the library works - architecture of the library

Index

Constants

View Source
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

func Connect

func Connect(database string) (*sql.DB, error)

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 GetExpenseById

func GetExpenseById(db meddler.DB, id int64) (*Expense, error)

func GetExpensesByLabel

func GetExpensesByLabel(db meddler.DB, label *Label) ([]*Expense, error)

func (*Expense) AddSimple

func (e *Expense) AddSimple(db meddler.DB, lender *User, debtor *User) (*Transaction, error)

Adds a single transaction. The entire expense amount is credited to the lender and charged to the debtor

func (*Expense) AddSplit

func (e *Expense) AddSplit(db meddler.DB, lender *User, debtors []*User) ([]*Transaction, error)

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

func (e *Expense) Remove(db meddler.DB) error

Removes the expense by reversing all transactions associated with it, and deleting the expense from the db

func (*Expense) String

func (e *Expense) String() string

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 Label

type Label struct {
	Id   int64  `meddler:"id,pk"`
	Name string `meddler:"name"`
}

func CreateLabel

func CreateLabel(db meddler.DB, name string) (*Label, error)

func GetLabelById

func GetLabelById(db meddler.DB, id int64) (*Label, error)

func GetLabelByName

func GetLabelByName(db meddler.DB, name string) (*Label, error)

func (*Label) String

func (l *Label) String() string

type MoneyAmount

type MoneyAmount struct {
	Dollars int
	Cents   int
}

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

type User

type User struct {
	Id      int64  `meddler:"id,pk"`
	Name    string `meddler:"name"`
	Email   string `meddler:"email"`
	Balance int    `meddler:"balance"`
}

func CreateUser

func CreateUser(db meddler.DB, name string, email string, balance int) (*User, error)

func GetUserById

func GetUserById(db meddler.DB, id int64) (*User, error)

func GetUserByName

func GetUserByName(db meddler.DB, name string) (*User, error)

func (*User) Reload

func (u *User) Reload(db meddler.DB) error

func (*User) String

func (u *User) String() string

func (*User) UpdateBalance

func (u *User) UpdateBalance(db meddler.DB, delta int) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL