diff --git a/internal/howmuch/model/event.go b/internal/howmuch/model/event.go index ecd866b..f2ded61 100644 --- a/internal/howmuch/model/event.go +++ b/internal/howmuch/model/event.go @@ -24,16 +24,39 @@ package model import "time" -type Event struct { +type EventCreateDTO struct { + Name string `json:"name" binding:"requiered"` + Description string `json:"description"` + OwnerID int `json:"owner_id" binding:"requiered,number"` +} + +type EventPO struct { ID int Name string Description string - Users []*User - Expenses []*Expense - TotalAmount Money - DefaultCurrency Currency - CreatedBy User + TotalAmount int + DefaultCurrency string + OwnerID int + + CreatedAt time.Time + UpdatedAt time.Time +} + +type Event struct { + ID int + + Name string + Description string + + // lazy get using participation join + Users []*User + // lazy get + Expenses []*Expense + + TotalAmount Money + DefaultCurrency Currency + Owner User CreatedAt time.Time UpdatedAt time.Time diff --git a/internal/howmuch/model/expense.go b/internal/howmuch/model/expense.go index 7515fad..6f6c091 100644 --- a/internal/howmuch/model/expense.go +++ b/internal/howmuch/model/expense.go @@ -24,20 +24,47 @@ package model import "time" -type ExpenseDetail struct { +type ExpenseDTO struct { + Amount Money `json:"money" binding:"required,number"` + PayerIDs []int `json:"payer_ids" binding:"required"` + RecipientIDs []int `json:"recipient_ids" binding:"required"` + EventID int `json:"event_id" binding:"required"` + Detail ExpenseDetail `json:"detail"` +} + +type ExpensePO struct { + ID int + + Amount int + Currency string + EventID int + + // ExpenseDetail Name string Place string + + CreatedAt time.Time + UpdatedAt time.Time +} + +type ExpenseDetail struct { + Name string `json:"name"` + Place string `json:"place"` } type Expense struct { ID int - Amount Money - Currency Currency - PayerIDs []int + Amount Money + + // Lazy aggregate using Transaction join + PayerIDs []int + + // Lazy aggregate using Transaction join RecipientIDs []int - EventID int - Detail ExpenseDetail + + EventID int + Detail ExpenseDetail CreatedAt time.Time UpdatedAt time.Time diff --git a/internal/howmuch/model/money.go b/internal/howmuch/model/money.go index 61d052f..b2f37d7 100644 --- a/internal/howmuch/model/money.go +++ b/internal/howmuch/model/money.go @@ -36,8 +36,8 @@ const ( ) type Money struct { - ammount int - currency Currency + Amount int `json:"amount" binding:"required,number"` + Currency Currency `json:"currency" binding:"required"` } func MakeMoney(amount int, currency Currency) Money { @@ -46,10 +46,10 @@ func MakeMoney(amount int, currency Currency) Money { func Add(cur Currency, money ...Money) Money { var sum Money - sum.currency = cur + sum.Currency = cur for _, m := range money { - sum.ammount += m.ammount + sum.Amount += m.Amount } return sum @@ -58,9 +58,9 @@ func Add(cur Currency, money ...Money) Money { func Diff(cur Currency, money1 Money, money2 Money) Money { var diff Money - diff.currency = cur + diff.Currency = cur - diff.ammount = money1.ammount - money2.ammount + diff.Amount = money1.Amount - money2.Amount return diff } diff --git a/internal/howmuch/model/participation.go b/internal/howmuch/model/participation.go index 1f215d4..c2a25b4 100644 --- a/internal/howmuch/model/participation.go +++ b/internal/howmuch/model/participation.go @@ -24,6 +24,8 @@ package model import "time" +type ParticipationPO Participation + // Participation is the association between Users and Events type Participation struct { ID int diff --git a/internal/howmuch/model/transaction.go b/internal/howmuch/model/transaction.go index 8f0fada..31ec8f5 100644 --- a/internal/howmuch/model/transaction.go +++ b/internal/howmuch/model/transaction.go @@ -24,14 +24,17 @@ package model import "time" +type TransactionPO Transaction + // Transaction is the association between Expenses and Users type Transaction struct { ID int ExpenseID Expense - PayerID int - Amount Money - Currency Currency + UserID int + Amount int + Currency string + IsIncome bool CreatedAt time.Time UpdatedAt time.Time diff --git a/internal/howmuch/model/user.go b/internal/howmuch/model/user.go index c6e7fd8..1e02ea2 100644 --- a/internal/howmuch/model/user.go +++ b/internal/howmuch/model/user.go @@ -36,8 +36,7 @@ type UserExistDTO struct { Password string `json:"password" binding:"required"` } -// User model -type User struct { +type UserPO struct { ID int Email string @@ -48,3 +47,19 @@ type User struct { CreatedAt time.Time UpdatedAt time.Time } + +// User model +type User struct { + ID int + + Email string + FirstName string + LastName string + Password string + + // Lazy aggregate with the Participation join + EventIDs []int + + CreatedAt time.Time + UpdatedAt time.Time +}