feat(tests): UpdateQuestion (full-replace) + ReorderQuestions
All checks were successful
CI / test (push) Successful in 14s
Build and Deploy / build-and-deploy (push) Successful in 27s

UpdateQuestion (PUT /tests/{id}/questions/{questionId}):
- транзакционно: UPDATE test_questions SET ... + DELETE test_answers +
  INSERT новых ответов. question_id стабилен — test_attempt_answers
  (FK CASCADE) остаются. Снимок ответа в payload — для будущего
  показа истории, в MVP не реализовано;
- семантика full-replace: проще на клиенте (один POST вместо
  per-answer патчей), атомарно на сервере.

ReorderQuestions (POST /tests/{id}/questions/reorder):
- батч-апдейт position через UNNEST(uuid[], int[]) — один запрос
  вместо N UPDATE'ов; идемпотентно;
- /reorder регистрируется ДО /{questionId} чтобы chi не заматчил
  его как questionId="reorder".

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ilya
2026-05-25 23:18:05 +03:00
parent 4f9b1b1491
commit 47a76bef7c
3 changed files with 198 additions and 1 deletions

View File

@@ -68,9 +68,12 @@ func main() {
r.Patch("/tests/{id}", testH.Update)
r.Delete("/tests/{id}", testH.Delete)
// Questions внутри теста
// Questions внутри теста. /reorder регистрируется ДО /{questionId},
// иначе chi заматчит {questionId} = "reorder".
r.Get("/tests/{id}/questions", testH.ListQuestions)
r.Post("/tests/{id}/questions", testH.CreateQuestion)
r.Post("/tests/{id}/questions/reorder", testH.ReorderQuestions)
r.Put("/tests/{id}/questions/{questionId}", testH.UpdateQuestion)
r.Delete("/tests/{id}/questions/{questionId}", testH.DeleteQuestion)
// Attempts: старт + получение + сабмит. Списки — отдельно