2025-09-17 19:30:17 +07:00

30 lines
778 B
Go

package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type CustomerPoints struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
CustomerID uuid.UUID `gorm:"type:uuid;not null;index" json:"customer_id" validate:"required"`
Balance int64 `gorm:"not null;default:0" json:"balance" validate:"min=0"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
Customer Customer `gorm:"foreignKey:CustomerID" json:"customer,omitempty"`
}
func (cp *CustomerPoints) BeforeCreate(tx *gorm.DB) error {
if cp.ID == uuid.Nil {
cp.ID = uuid.New()
}
return nil
}
func (CustomerPoints) TableName() string {
return "customer_points"
}