Documentation
¶
Index ¶
- Variables
- func BillSplitDeleteAll() (err error)
- func ExpenseDeleteAll() (err error)
- func GetEnv(key, fallback string) string
- func InitDb()
- func ParticipantDeleteAll() (err error)
- func ParticipantExpenseDeleteAll() (err error)
- func ReplaceSQL(old, searchPattern string, startCount int) string
- func SetupDB()
- type BillSplit
- func BillSplitByID(id int) (billSplit BillSplit, err error)
- func BillSplitByName(name string) (billSplit BillSplit, err error)
- func BillSplitByUUID(uuid string) (billSplit BillSplit, err error)
- func BillSplits() (billSplits []BillSplit, err error)
- func CreateBillSplit(name string) (billsplit BillSplit, err error)
- func (billSplit *BillSplit) CreateExpense(name string, amount float64, participantName string) (expense Expense, err error)
- func (billSplit *BillSplit) CreateExpenseParticipants(uuid string, participantNames []string) (err error)
- func (billSplit *BillSplit) CreateParticipant(name string) (participant Participant, err error)
- func (billSplit *BillSplit) CreateParticipants(names []string) (err error)
- func (billSplit *BillSplit) ExpenseByUuid(name string) (expense Expense, err error)
- func (billSplit *BillSplit) Expenses() (items []Expense, err error)
- func (billSplit *BillSplit) GetDebts() (debts []Debt, err error)
- func (billSplit *BillSplit) GetFullBalance() (fullBalance map[string]float64, err error)
- func (billSplit *BillSplit) ParticipantByName(name string) (participant Participant, err error)
- func (billSplit *BillSplit) Participants() (items []Participant, err error)
- func (billSplit *BillSplit) ParticipantsByName(names []string) (items []Participant, err error)
- type Debt
- type Expense
- type JSONTime
- type Participant
Constants ¶
This section is empty.
Variables ¶
var ( // DB_USER database username DB_USER = GetEnv("DB_USER", "postgres") // DB_PASSWORD username password DB_PASSWORD = GetEnv("DB_PASSWORD", "password") // DB_NAME database name DB_NAME = GetEnv("DB_NAME", "test_bill") // DB_HOST database connection host DB_HOST = GetEnv("DB_HOST", "localhost") // DB_PORT database connection port DB_PORT = GetEnv("DB_PORT", "5432") )
var Db *sql.DB
Db is the global Database variable
Functions ¶
func BillSplitDeleteAll ¶
func BillSplitDeleteAll() (err error)
BillSplitDeleteAll deletes all BillSplits from database
func ExpenseDeleteAll ¶
func ExpenseDeleteAll() (err error)
ExpenseDeleteAll deletes all Expenses from database
func InitDb ¶
func InitDb()
InitDb initializes and opens a connection to the Database with the env vars parameters
func ParticipantDeleteAll ¶
func ParticipantDeleteAll() (err error)
ParticipantDeleteAll deletes all Participants from database
func ParticipantExpenseDeleteAll ¶
func ParticipantExpenseDeleteAll() (err error)
ParticipantExpenseDeleteAll deletes all ParticipantExpense from database
func ReplaceSQL ¶
ReplaceSQL replaces the instance occurrence of any string pattern with an increasing $n based sequence
Types ¶
type BillSplit ¶
BillSplit holds DB info of a bill split
func BillSplitByID ¶
BillSplitByID gets a BillSplit record in the DB by its id
func BillSplitByName ¶
BillSplitByName gets a BillSplit record in the DB by its name (unique)
func BillSplitByUUID ¶
BillSplitByUUID gets a BillSplit record in the DB by its uuid
func BillSplits ¶
BillSplits gets all BillSplit records in the DB
func CreateBillSplit ¶
CreateBillSplit create a new BillSplit in the DB
func (*BillSplit) CreateExpense ¶
func (billSplit *BillSplit) CreateExpense(name string, amount float64, participantName string) (expense Expense, err error)
CreateExpense creates a new expense to the billsplit name: name of the expense to create amount: amount of the expense participantName: payer of the expense
func (*BillSplit) CreateExpenseParticipants ¶
func (billSplit *BillSplit) CreateExpenseParticipants(uuid string, participantNames []string) (err error)
CreateExpenseParticipants add participants to an existing expense uuid: uuid of the expense participantNames: participants to the expense
func (*BillSplit) CreateParticipant ¶
func (billSplit *BillSplit) CreateParticipant(name string) (participant Participant, err error)
CreateParticipant creates a new participant name: name of the participant to create
func (*BillSplit) CreateParticipants ¶
CreateParticipants creates new participants to the billsplit name: names of the participants to create
func (*BillSplit) ExpenseByUuid ¶
ExpenseByUuid gets an expense in the DB by uuid
func (*BillSplit) GetFullBalance ¶
GetFullBalance gets the balance of each participants
func (*BillSplit) ParticipantByName ¶
func (billSplit *BillSplit) ParticipantByName(name string) (participant Participant, err error)
ParticipantByName gets a Participant in the DB by name
func (*BillSplit) Participants ¶
func (billSplit *BillSplit) Participants() (items []Participant, err error)
Participants gets all participants in the DB to a BillSplit
func (*BillSplit) ParticipantsByName ¶
func (billSplit *BillSplit) ParticipantsByName(names []string) (items []Participant, err error)
ParticipantsByName gets a Participants in the DB by name names: names of the participants to get
type Debt ¶
Debt is a struct for debt description: Debtor: participant that owes money Creditor: participant that claims money
type Expense ¶
type Expense struct { Id int Uuid string Name string Amount float64 BillSplitID int PayerName string CreatedAt JSONTime }
Expense struct has info of an Expense
func ExpenseByUuid ¶
ExpenseByUuid gets an Expense record in the DB by its uuid (unique)
func (*Expense) AddParticipant ¶
AddParticipant adds one participants to an expense
func (*Expense) AddParticipants ¶
AddParticipants adds multiple participants to an expense
func (*Expense) ExpenseParticipants ¶
ExpenseParticipants gets the participants to and expense
type JSONTime ¶
JSONTime is a time.Time type that implements MarshalJSON in order to have a custom time format
func (JSONTime) MarshalJSON ¶
MarshalJSON returns custom time format
type Participant ¶
Participant struct has info of a Participant
func ParticipantByID ¶
func ParticipantByID(id int) (participant Participant, err error)
ParticipantByID gets an Participant record in the DB by its id (unique)
func ParticipantByName ¶
func ParticipantByName(uuid string, billsplitID int) (participant Participant, err error)
ParticipantByName gets an Participant record in the DB by its name and billsplit ID (unique)
func ParticipantByUUID ¶
func ParticipantByUUID(uuid string) (participant Participant, err error)
ParticipantByUUID gets an Participant record in the DB by its uuid (unique)