nquest/pkg/models/team.go

38 lines
1.1 KiB
Go
Raw Normal View History

2023-11-01 23:21:12 +03:00
package models
import (
"time"
)
type Team struct {
Model
Name string `gorm:"unique,not_null" json:"name"`
Members []*TeamMember `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"members"`
Requests []*TeamRequest `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-"`
Games []*TeamAtGame `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"-"`
}
type TeamMember struct {
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"team"`
TeamID uint `gorm:"primaryKey" json:"-"`
User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"-"`
UserID uint `gorm:"primaryKey" json:"-"`
Role Role `json:"role"`
CreatedAt time.Time `json:"-"`
}
type TeamRequest struct {
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
TeamID uint `gorm:"primaryKey"`
User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
UserID uint `gorm:"primaryKey"`
CreatedAt time.Time
}
type Role int
const (
Captain Role = iota
Member
)