Added expenses to plan
This commit is contained in:
parent
8ea8574f3f
commit
54d7d14ef9
9 changed files with 401 additions and 13 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package core
|
||||
|
||||
import "github.com/shopspring/decimal"
|
||||
|
||||
type User struct {
|
||||
Username string `gorm:"primaryKey" json:"username"`
|
||||
Password string `json:"password"`
|
||||
|
|
@ -12,9 +14,8 @@ type Member struct {
|
|||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"-"`
|
||||
PlanID uint `json:"-"`
|
||||
Plan Plan `json:"-"`
|
||||
Type string `gorm:"check:type in ('user','non-user')" json:"type"`
|
||||
Name string `gorm:"check:type=='member' OR name IS NOT NULL" json:"name"`
|
||||
UserID string `json:"username"`
|
||||
Name string `gorm:"check:user_id IS NOT NULL OR name IS NOT NULL" json:"name,omitempty"`
|
||||
UserID string `json:"username,omitempty"`
|
||||
User User `gorm:"foreignKey:UserID" json:"-"`
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +31,25 @@ type Plan struct {
|
|||
Polls []Poll `gorm:"foreignKey:PlanID;references:ID" json:"-"`
|
||||
}
|
||||
|
||||
type Expense struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
PlanID uint `json:"-"`
|
||||
Plan Plan `json:"-"`
|
||||
PayerID uint `json:"-"`
|
||||
Payer Member `gorm:"foreignKey:PayerID" json:"-"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Debts []Debt `gorm:"foreignKey:ExpenseID" json:"debts,omitempty"`
|
||||
}
|
||||
|
||||
type Debt struct {
|
||||
ExpenseID uint `gorm:"primaryKey" json:"-"`
|
||||
Expense Expense `gorm:"foreignKey:ExpenseID"`
|
||||
DebtorID uint `gorm:"primaryKey" json:"-"`
|
||||
Debtor Member `gorm:"foreignKey:DebtorID"`
|
||||
Amount decimal.Decimal
|
||||
Paid decimal.Decimal
|
||||
}
|
||||
|
||||
// CREATE TABLE polls(id INTEGER PRIMARY KEY AUTOINCREMENT, plan INTEGER, name STRING, options JSON, FOREIGN KEY plan REFERENCES plans(id))
|
||||
type Poll struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue