Перейти к содержанию

API: Exam

Базовый URL: http://localhost:8001. Префикс: /api/exam.

Auth: Bearer JWT.
Гейт: MEDICAL_ASSISTANT_ENABLED + LEARNING_ROLES.

При первом списке — ensure_seed_tests (seed EN+RU, идемпотентно по title).


GET /api/exam

Список тестов.

Query

Параметр Описание
language en | ru
category Категория
difficulty Сложность

Response 200

{
  "items": [
    {
      "id": "…",
      "title": "…",
      "description": "…",
      "category": "cardiology",
      "difficulty": "intermediate",
      "questions": [
        {"question": "…", "options": ["A", "B", "C", "D"]}
      ],
      "created_at": "…"
    }
  ]
}

correct_index и explanation скрыты до сабмита.


GET /api/exam/{test_id}

Один тест. 404 если нет.


POST /api/exam/generate

Request

{
  "category": "cardiology",
  "difficulty": "intermediate",
  "num_questions": 5,
  "language": "en",
  "persist": true
}
Поле Ограничения
category обязательно
difficulty default intermediate
num_questions 1–20, default 5
language default en
persist default true

Response 200 — сохранённый тест или сырой payload.


POST /api/exam/{test_id}/submit

Request

{
  "answers": [0, 2, 1, 3, 0],
  "time_spent": 600
}

answers — список индексов вариантов (по порядку вопросов), минимум 1 элемент.

Response 200

{
  "score": 80.0,
  "correct": 4,
  "total": 5,
  "details": [
    {
      "index": 0,
      "correct": true,
      "selected": 0,
      "correct_index": 0,
      "explanation": "…"
    }
  ]
}

Прогресс: module=exam, score = процент, extra_data.test_id / correct.


Пример curl

curl -s -X POST http://localhost:8001/api/exam/$TEST_ID/submit \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{"answers":[0,1,2],"time_spent":120}'