simple POC
All checks were successful
build / windows (push) Successful in 5m37s
build / linux (push) Successful in 4m20s

This commit is contained in:
2025-03-10 11:25:38 +01:00
parent 037b593c6b
commit b107b926a2
17 changed files with 364 additions and 210 deletions

View File

@ -9,9 +9,33 @@ import (
"gorm.io/gorm"
)
type Thing struct {
ID int
Name string
type Game struct {
gorm.Model
TeamA int `gorm:"-"`
TeamB int `gorm:"-"`
Steps []Step `gorm:"foreignKey:GameID"`
}
func (g *Game) SumPoints() {
g.TeamA = 0
g.TeamB = 0
for _, s := range g.Steps {
g.TeamA += s.PointsTeamA + s.AdderTeamA
g.TeamB += s.PointsTeamB + s.AdderTeamB
}
}
type Step struct {
gorm.Model
GameID uint
Game Game `gorm:"foreignKey:GameID"`
PointsTeamA int
AdderTeamA int
PointsTeamB int
AdderTeamB int
}
func InitDB() *gorm.DB {
@ -19,10 +43,10 @@ func InitDB() *gorm.DB {
if err != nil {
panic(err)
}
db, err := gorm.Open(sqlite.Open(path.Join(home, "things.db")))
db, err := gorm.Open(sqlite.Open(path.Join(home, "tichu.db")))
if err != nil {
log.Panic(err)
}
db.AutoMigrate(&Thing{})
db.AutoMigrate(Game{}, Step{})
return db
}