feat: rework entities design
This commit is contained in:
parent
dfc2d1b2eb
commit
0e05924585
@ -24,16 +24,39 @@ package model
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
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
|
||||||
|
TotalAmount int
|
||||||
|
DefaultCurrency string
|
||||||
|
OwnerID int
|
||||||
|
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
ID int
|
ID int
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
|
// lazy get using participation join
|
||||||
Users []*User
|
Users []*User
|
||||||
|
// lazy get
|
||||||
Expenses []*Expense
|
Expenses []*Expense
|
||||||
|
|
||||||
TotalAmount Money
|
TotalAmount Money
|
||||||
DefaultCurrency Currency
|
DefaultCurrency Currency
|
||||||
CreatedBy User
|
Owner User
|
||||||
|
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
@ -24,18 +24,45 @@ package model
|
|||||||
|
|
||||||
import "time"
|
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
|
Name string
|
||||||
Place string
|
Place string
|
||||||
|
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExpenseDetail struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Place string `json:"place"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Expense struct {
|
type Expense struct {
|
||||||
ID int
|
ID int
|
||||||
|
|
||||||
Amount Money
|
Amount Money
|
||||||
Currency Currency
|
|
||||||
|
// Lazy aggregate using Transaction join
|
||||||
PayerIDs []int
|
PayerIDs []int
|
||||||
|
|
||||||
|
// Lazy aggregate using Transaction join
|
||||||
RecipientIDs []int
|
RecipientIDs []int
|
||||||
|
|
||||||
EventID int
|
EventID int
|
||||||
Detail ExpenseDetail
|
Detail ExpenseDetail
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Money struct {
|
type Money struct {
|
||||||
ammount int
|
Amount int `json:"amount" binding:"required,number"`
|
||||||
currency Currency
|
Currency Currency `json:"currency" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeMoney(amount int, currency Currency) Money {
|
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 {
|
func Add(cur Currency, money ...Money) Money {
|
||||||
var sum Money
|
var sum Money
|
||||||
sum.currency = cur
|
sum.Currency = cur
|
||||||
|
|
||||||
for _, m := range money {
|
for _, m := range money {
|
||||||
sum.ammount += m.ammount
|
sum.Amount += m.Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum
|
return sum
|
||||||
@ -58,9 +58,9 @@ func Add(cur Currency, money ...Money) Money {
|
|||||||
func Diff(cur Currency, money1 Money, money2 Money) Money {
|
func Diff(cur Currency, money1 Money, money2 Money) Money {
|
||||||
var diff Money
|
var diff Money
|
||||||
|
|
||||||
diff.currency = cur
|
diff.Currency = cur
|
||||||
|
|
||||||
diff.ammount = money1.ammount - money2.ammount
|
diff.Amount = money1.Amount - money2.Amount
|
||||||
|
|
||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ package model
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
type ParticipationPO Participation
|
||||||
|
|
||||||
// Participation is the association between Users and Events
|
// Participation is the association between Users and Events
|
||||||
type Participation struct {
|
type Participation struct {
|
||||||
ID int
|
ID int
|
||||||
|
@ -24,14 +24,17 @@ package model
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
type TransactionPO Transaction
|
||||||
|
|
||||||
// Transaction is the association between Expenses and Users
|
// Transaction is the association between Expenses and Users
|
||||||
type Transaction struct {
|
type Transaction struct {
|
||||||
ID int
|
ID int
|
||||||
|
|
||||||
ExpenseID Expense
|
ExpenseID Expense
|
||||||
PayerID int
|
UserID int
|
||||||
Amount Money
|
Amount int
|
||||||
Currency Currency
|
Currency string
|
||||||
|
IsIncome bool
|
||||||
|
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
@ -36,8 +36,7 @@ type UserExistDTO struct {
|
|||||||
Password string `json:"password" binding:"required"`
|
Password string `json:"password" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// User model
|
type UserPO struct {
|
||||||
type User struct {
|
|
||||||
ID int
|
ID int
|
||||||
|
|
||||||
Email string
|
Email string
|
||||||
@ -48,3 +47,19 @@ type User struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt 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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user