all repos — piggy @ d8748d219af2eb8f80b1589a04f72614d5638b86

Dead simple finance manager in Go, HTML and JS.

src/app/models.go (view raw)

 1package app
 2
 3import (
 4	"time"
 5)
 6
 7type Bookmaker struct {
 8	ID        uint      `json:"id"`
 9	CreatedAt time.Time `json:"created_at"`
10	UpdatedAt time.Time `json:"updated_at"`
11
12	Name              string `json:"name" gorm:"not null" `
13	DefaultCommission uint   `json:"default_commission" gorm:"not null"`
14}
15
16type Account struct {
17	ID        uint      `json:"id"`
18	CreatedAt time.Time `json:"created_at"`
19	UpdatedAt time.Time `json:"updated_at"`
20
21	Name string `json:"name" gorm:"not null"`
22}
23
24type Record struct {
25	ID        uint      `json:"id" gorm:"primaryKey"`
26	CreatedAt time.Time `json:"created_at"`
27	UpdatedAt time.Time `json:"updated_at"`
28
29	Done        bool   `json:"done" gorm:"not null"`
30	Type        string `json:"type" gorm:"not null"`
31	Description string `json:"description" gorm:"not null"`
32
33	Date  *time.Time `json:"date" gorm:"-"`
34	Value *int       `json:"value" gorm:"-"`
35
36	Entries []Entry `json:"entries" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
37}
38
39type Entry struct {
40	ID        uint      `json:"id"`
41	CreatedAt time.Time `json:"created_at"`
42	UpdatedAt time.Time `json:"updated_at"`
43
44	RecordID    uint `json:"record_id" gorm:"not null"`
45	BookmakerID uint `json:"bookmaker_id" gorm:"not null"`
46	AccountID   uint `json:"account_id" gorm:"not null"`
47	Amount      uint `json:"amount" gorm:"not null"`     // In cents (ex: 100 = 1.00)
48	Refund      uint `json:"refund" gorm:"not null"`     // In cents (ex: 100 = 1.00)
49	Bonus       uint `json:"bonus" gorm:"not null"`      // In cents (ex: 50 = 0.50)
50	Commission  uint `json:"commission" gorm:"not null"` // In cents (ex: 4.5% = 450)
51
52	Odds  *uint      `json:"odds" gorm:"-"`
53	Won   *bool      `json:"won" gorm:"-"`
54	Date  *time.Time `json:"date" gorm:"-"`
55	Value *int       `json:"value" gorm:"-"`
56
57	Bookmaker  Bookmaker  `json:"bookmaker" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
58	Account    Account    `json:"account" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
59	SubEntries []SubEntry `json:"sub_entries" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
60}
61
62type SubEntry struct {
63	ID        uint      `json:"id"`
64	CreatedAt time.Time `json:"created_at"`
65	UpdatedAt time.Time `json:"updated_at"`
66
67	EntryID     uint      `json:"entry_id" gorm:"not null"`
68	Description string    `json:"description" gorm:"not null"`
69	Odds        uint      `json:"odds" gorm:"not null"` // In cents (ex: 200 = 2.00)
70	Won         bool      `json:"won" gorm:"not null"`
71	Date        time.Time `json:"date" gorm:"not null;default:current_timestamp"`
72
73	Value *int `json:"value" gorm:"-"`
74}