41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type GameType string
|
|
|
|
const (
|
|
GameTypeSpin GameType = "SPIN"
|
|
GameTypeRaffle GameType = "RAFFLE"
|
|
GameTypeMinigame GameType = "MINIGAME"
|
|
)
|
|
|
|
type Game struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
|
Name string `gorm:"type:varchar(255);not null" json:"name" validate:"required"`
|
|
Type GameType `gorm:"type:varchar(50);not null" json:"type" validate:"required,oneof=SPIN RAFFLE MINIGAME"`
|
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
|
Metadata Metadata `gorm:"type:jsonb;default:'{}'" json:"metadata"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
Prizes []GamePrize `gorm:"foreignKey:GameID" json:"prizes,omitempty"`
|
|
Plays []GamePlay `gorm:"foreignKey:GameID" json:"plays,omitempty"`
|
|
}
|
|
|
|
func (g *Game) BeforeCreate(tx *gorm.DB) error {
|
|
if g.ID == uuid.Nil {
|
|
g.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (Game) TableName() string {
|
|
return "games"
|
|
}
|