add match history

This commit is contained in:
2026-11-15 18:27:05 +03:00
parent 93b883dfba
commit 8f70bb639d
11 changed files with 954 additions and 11 deletions
+68
View File
@@ -325,6 +325,72 @@ Action Cable использует формат JSON-сообщений чере
---
### История матчей
Возвращает постраничный список матчей текущего авторизованного пользователя, отсортированный от новых к старым (по дате начала `started_at`).
**URL:** `GET /api/matches`
**Auth:** требуется (JWT пользователя)
**Параметры query string:**
| Параметр | Тип | Обязательный | По умолчанию | Описание |
|----------|-----|--------------|--------------|----------|
| `start` / `from` | integer | — | `0` | Смещение (offset) от начала списка |
| `count` | integer | — | `20` | Количество возвращаемых матчей (максимум 100) |
**Пример запроса:**
```bash
curl -X GET "http://localhost:3000/api/matches?start=0&count=10" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..."
```
**Успешный ответ (200 OK):**
```json
{
"matches": [
{
"id": "145575d6-3a4b-4c5d-9e6f-7a8b9c0d1e2f",
"status": "player1_won",
"game_server": "ws://localhost:8081/ws",
"started_at": "2026-11-09T12:00:00.000Z",
"finished_at": "2026-11-09T12:02:05.000Z",
"duration_seconds": 125,
"player1": {
"id": 1,
"nickname": "CaptainNemo",
"avatar_url": "http://localhost:3000/rails/active_storage/blobs/...",
"rating_before": 100,
"rating_change": 0
},
"player2": {
"id": 2,
"nickname": "CaptainHook",
"avatar_url": null,
"rating_before": 100,
"rating_change": 0
},
"your_rating_before": 100,
"your_rating_change": 0
}
],
"total": 1,
"start": 0,
"count": 10
}
```
**Ошибки:**
| Код | Описание |
|-----|----------|
| `401` | отсутствует/невалиден токен |
---
### Детали матча
Возвращает подробную информацию о матче: итог, длительность и дельту рейтинга
@@ -362,12 +428,14 @@ curl -X GET http://localhost:3000/api/matches/145575d6-3a4b-4c5d-9e6f-7a8b9c0d1e
"player1": {
"id": 1,
"nickname": "CaptainNemo",
"avatar_url": "http://localhost:3000/rails/active_storage/blobs/...",
"rating_before": 100,
"rating_change": 0
},
"player2": {
"id": 2,
"nickname": "CaptainHook",
"avatar_url": null,
"rating_before": 100,
"rating_change": 0
},