init
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type PaymentOrderItem struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
PaymentID uuid.UUID `gorm:"type:uuid;not null;index" json:"payment_id"`
|
||||
OrderItemID uuid.UUID `gorm:"type:uuid;not null;index" json:"order_item_id"`
|
||||
Amount float64 `gorm:"type:decimal(10,2);not null" json:"amount"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
|
||||
Payment Payment `gorm:"foreignKey:PaymentID" json:"payment,omitempty"`
|
||||
OrderItem OrderItem `gorm:"foreignKey:OrderItemID" json:"order_item,omitempty"`
|
||||
}
|
||||
|
||||
func (poi *PaymentOrderItem) BeforeCreate(tx *gorm.DB) error {
|
||||
if poi.ID == uuid.Nil {
|
||||
poi.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (PaymentOrderItem) TableName() string {
|
||||
return "payment_order_items"
|
||||
}
|
||||
Reference in New Issue
Block a user