complete game pls

main
Bel LaPointe 2024-12-15 01:45:25 -07:00
parent 9dd661ecd0
commit 130f8122b6
2 changed files with 22 additions and 5 deletions

View File

@ -250,11 +250,11 @@ func (games Games) CreateGame(ctx context.Context, name string) (string, error)
func (games Games) CreateEventPlayerJoin(ctx context.Context, id string, player string) error {
if err := games.db.Exec(ctx, `
INSERT INTO players (
game_uuid,
user_uuid
) VALUES (?, ?)
`, id, player); err != nil {
INSERT INTO players (
game_uuid,
user_uuid
) VALUES (?, ?)
`, id, player); err != nil {
return err
}
return games.createEvent(ctx, id, EventPlayerJoin{Type: PlayerJoin, ID: player})
@ -337,10 +337,19 @@ func (games Games) CreateEventAssignmentRotation(ctx context.Context, id string,
}() {
}
// TODO generate .Global, .Assignments.Public, .Assignments.Private and
return games.createEvent(ctx, id, event)
}
func (games Games) CreateEventGameComplete(ctx context.Context, id string) error {
if err := games.db.Exec(ctx, `
UPDATE games
SET completed=?, updated=?
WHERE uuid=?
`, time.Now(), time.Now(), id); err != nil {
return err
}
return games.createEvent(ctx, id, EventGameComplete{Type: GameComplete})
}

View File

@ -104,5 +104,13 @@ func TestGames(t *testing.T) {
}
}
}
if err := games.CreateEventGameComplete(ctx, id); err != nil {
t.Fatal("err creating game complete:", err)
} else if state, err := games.GameState(ctx, id); err != nil {
t.Fatal("err fetching state after completing:", err)
} else if state.Completed.IsZero() {
t.Fatal("state.Completed is zero")
}
})
}