add private endpoint for match reporting

This commit is contained in:
2026-11-09 23:17:55 +03:00
parent f0616c7c51
commit dcb76fa570
11 changed files with 738 additions and 4 deletions
@@ -0,0 +1,39 @@
# Serializes a Match as the JSON representation shared by the internal
# (game-server facing) and the player-facing endpoints. When `viewer` is
# given, the viewer's own rating delta is included under `your_rating_before`
# and `your_rating_change`.
class MatchSerializer
def self.as_json(match, viewer: nil)
match_json = {
id: match.uuid,
status: match.status,
game_server: match.game_server,
started_at: match.started_at,
finished_at: match.finished_at,
duration_seconds: match.duration_seconds,
player1: player_json(match.player1, match.player1_rating_before, match.player1_rating_change),
player2: player_json(match.player2, match.player2_rating_before, match.player2_rating_change)
}
if viewer
if viewer.id == match.player1_id
match_json[:your_rating_before] = match.player1_rating_before
match_json[:your_rating_change] = match.player1_rating_change
elsif viewer.id == match.player2_id
match_json[:your_rating_before] = match.player2_rating_before
match_json[:your_rating_change] = match.player2_rating_change
end
end
match_json
end
def self.player_json(user, rating_before, rating_change)
{
id: user.id,
nickname: user.nickname,
rating_before: rating_before,
rating_change: rating_change
}
end
end