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 { func (games Games) CreateEventPlayerJoin(ctx context.Context, id string, player string) error {
if err := games.db.Exec(ctx, ` if err := games.db.Exec(ctx, `
INSERT INTO players ( INSERT INTO players (
game_uuid, game_uuid,
user_uuid user_uuid
) VALUES (?, ?) ) VALUES (?, ?)
`, id, player); err != nil { `, id, player); err != nil {
return err return err
} }
return games.createEvent(ctx, id, EventPlayerJoin{Type: PlayerJoin, ID: player}) 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) return games.createEvent(ctx, id, event)
} }
func (games Games) CreateEventGameComplete(ctx context.Context, id string) error { 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}) 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")
}
}) })
} }