package entities import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type ExpenseItem struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` ExpenseID uuid.UUID `gorm:"type:uuid;not null;index" json:"expense_id"` ChartOfAccountID uuid.UUID `gorm:"type:uuid;not null;index" json:"chart_of_account_id"` Description *string `gorm:"type:text" json:"description"` Amount float64 `gorm:"type:decimal(15,2);not null;default:0" json:"amount"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` Expense *Expense `gorm:"foreignKey:ExpenseID" json:"expense,omitempty"` ChartOfAccount *ChartOfAccount `gorm:"foreignKey:ChartOfAccountID" json:"chart_of_account,omitempty"` } func (e *ExpenseItem) BeforeCreate(tx *gorm.DB) error { if e.ID == uuid.Nil { e.ID = uuid.New() } return nil } func (ExpenseItem) TableName() string { return "expense_items" }