nquest/pkg/models/game.go

56 lines
1.4 KiB
Go
Raw Normal View History

2023-11-01 23:21:12 +03:00
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
2023-11-19 22:54:54 +03:00
Authors []*User `gorm:"many2many:game_authors"`
2023-11-01 23:21:12 +03:00
}
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
)