Show user's active games on home page after login

This commit is contained in:
Ryan Hamamura
2026-01-14 17:11:27 -10:00
parent 2153b6ad75
commit d96f7dcc29
5 changed files with 250 additions and 1 deletions

View File

@@ -29,3 +29,17 @@ SELECT g.* FROM games g
JOIN game_players gp ON g.id = gp.game_id
WHERE gp.user_id = ?
ORDER BY g.updated_at DESC;
-- name: GetUserActiveGames :many
SELECT
g.id,
g.status,
g.current_turn,
g.updated_at,
gp_user.color as my_color,
gp_opponent.nickname as opponent_nickname
FROM games g
JOIN game_players gp_user ON g.id = gp_user.game_id AND gp_user.user_id = ?
LEFT JOIN game_players gp_opponent ON g.id = gp_opponent.game_id AND gp_opponent.slot != gp_user.slot
WHERE g.status < 2
ORDER BY g.updated_at DESC;