Skip to content

Commit

Permalink
fix: store rank after completed game
Browse files Browse the repository at this point in the history
Closes: #40
  • Loading branch information
Evans Owamoyo committed Jan 9, 2025
1 parent 180cfff commit 1b73aa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ func (s *Session) BestGuess() word.Word {
}

func (s *Session) WordsCount() int {
if v := len(s.Guesses); v != 0 {
return v
if s.wordsCount != 0 {
return s.wordsCount
}
return s.wordsCount
return len(s.Guesses)
}

func (s *Session) GreaterThan(other *Session) bool {
Expand Down
6 changes: 5 additions & 1 deletion repository/postgres/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func (r *GameRepo) FinishGame(ctx context.Context, g *game.Game) error {
Time: s.BestGuess().PlayedAt.Time,
Valid: s.Won(),
},
Rank: pgtype.Int4{
Int32: int32(g.Leaderboard.Positions[s.Player.Username]),
Valid: true,
},
})
}
// commit
Expand Down Expand Up @@ -233,7 +237,7 @@ func NewGameRepo(db *pgxpool.Pool) *GameRepo {

func toGame(g pgen.PlayerGamesRow) game.Game {
return game.Game{
ID: uuid.UUID(g.ID.Bytes),
ID: g.ID.Bytes,
Creator: g.CreatorUsername,
CorrectWord: word.New(g.CorrectWord),
CreatedAt: g.CreatedAt.Time,
Expand Down

0 comments on commit 1b73aa5

Please sign in to comment.