apskel-pos-backend/internal/entities/payment_order_item.go

32 lines
925 B
Go
Raw Normal View History

2025-07-18 20:10:29 +07:00
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"
}