nquest/pkg/models/game.go

54 lines
1.3 KiB
Go

package models
import (
"time"
)
type Game struct {
Model
Visible bool `gorm:"index"`
Title string
Description string
StartAt time.Time
Teams []*TeamAtGame `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Tasks []*Task `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
FirstTask *Task `gorm:"foreignKey:ID"`
FirstTaskID uint
}
type TeamAtGame struct {
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
TeamID uint `gorm:"primaryKey"`
Game *Game `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
GameID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
}
type GamePassing struct {
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
TeamID uint `gorm:"primaryKey"`
Game *Game `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
GameID uint `gorm:"primaryKey"`
Task *Task `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
TaskID uint `gorm:"primaryKey"`
CreatedAt time.Time
FinishedAt *time.Time
Deadline time.Time
Status Passing
Codes []*Code `gorm:"many2many:passing_codes;"`
}
func (g *GamePassing) Timeouted() bool {
return g.Deadline.Before(time.Now())
}
type Passing int
const (
PassStarted Passing = iota
PassFinished
PassCanceled
PassFailed
)