29 lines
718 B
Go
29 lines
718 B
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Tier struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
|
Name string `gorm:"type:varchar(100);not null;unique" json:"name" validate:"required"`
|
|
MinPoints int64 `gorm:"not null" json:"min_points" validate:"min=0"`
|
|
Benefits Metadata `gorm:"type:jsonb;default:'{}'" json:"benefits"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
}
|
|
|
|
func (t *Tier) BeforeCreate(tx *gorm.DB) error {
|
|
if t.ID == uuid.Nil {
|
|
t.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (Tier) TableName() string {
|
|
return "tiers"
|
|
}
|