refactor: add save()/savePlayer() methods on game instances
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped

Wrap free persistence functions in instance methods for cleaner call
sites (gi.save() instead of saveGame(gi.queries, gi.game)). Methods
log errors via zerolog before returning them.
This commit is contained in:
Ryan Hamamura
2026-03-02 18:51:18 -10:00
parent cb5458c9fc
commit 9a20467438
5 changed files with 48 additions and 12 deletions

View File

@@ -49,7 +49,7 @@ func (gs *GameStore) Create() *GameInstance {
gs.gamesMu.Unlock()
if gs.queries != nil {
saveGame(gs.queries, gi.game) //nolint:errcheck
gi.save() //nolint:errcheck
}
return gi
@@ -152,8 +152,8 @@ func (gi *GameInstance) Join(ps *PlayerSession) bool {
}
if gi.queries != nil {
saveGamePlayer(gi.queries, gi.game.ID, ps.Player, slot) //nolint:errcheck
saveGame(gi.queries, gi.game) //nolint:errcheck
gi.savePlayer(ps.Player, slot) //nolint:errcheck
gi.save() //nolint:errcheck
}
gi.notify()
@@ -190,7 +190,7 @@ func (gi *GameInstance) CreateRematch(gs *GameStore) *GameInstance {
gi.game.RematchGameID = &newID
if gi.queries != nil {
if err := saveGame(gi.queries, gi.game); err != nil {
if err := gi.save(); err != nil {
gs.Delete(newID) //nolint:errcheck
gi.game.RematchGameID = nil
return nil
@@ -224,7 +224,7 @@ func (gi *GameInstance) DropPiece(col int, playerColor int) bool {
}
if gi.queries != nil {
saveGame(gi.queries, gi.game) //nolint:errcheck
gi.save() //nolint:errcheck
}
gi.notify()