refactor(gameplay): extract round start payload builders
All checks were successful
CI / test-and-quality (push) Successful in 3m51s
CI / test-and-quality (pull_request) Successful in 3m53s

This commit is contained in:
2026-03-17 19:15:44 +00:00
parent c45f04f9f1
commit 16c9cf6b57
3 changed files with 60 additions and 44 deletions

View File

@@ -13,9 +13,12 @@ from fupogfakta.payloads import (
build_leaderboard as _build_leaderboard,
build_lie_started_payload as _build_lie_started_payload,
build_phase_view_model as _build_phase_view_model,
build_question_shown_payload as _build_question_shown_payload,
build_question_shown_response as _build_question_shown_response,
build_reveal_payload as _build_reveal_payload,
build_round_question_payload as _build_round_question_payload,
build_scoreboard_phase_event as _build_scoreboard_phase_event,
build_start_round_response as _build_start_round_response,
)
from fupogfakta.services import (
finish_game as _finish_game,
@@ -315,30 +318,7 @@ def start_round(request: HttpRequest, code: str) -> JsonResponse:
)
return JsonResponse(
{
"session": {
"code": session.code,
"status": session.status,
"current_round": session.current_round,
},
"round": {
"number": round_config.number,
"category": {
"slug": round_config.category.slug,
"name": round_config.category.name,
},
},
"round_question": {
"id": round_question.id,
"prompt": round_question.question.prompt,
"round_number": round_question.round_number,
"shown_at": round_question.shown_at.isoformat(),
"lie_deadline_at": lie_started_payload["lie_deadline_at"],
},
"config": {
"lie_seconds": round_config.lie_seconds,
},
},
_build_start_round_response(session, round_config, round_question),
status=201,
)
@@ -391,31 +371,16 @@ def show_question(request: HttpRequest, code: str) -> JsonResponse:
lie_deadline_at = round_question.shown_at + timedelta(seconds=round_config.lie_seconds)
lie_deadline_iso = lie_deadline_at.isoformat()
sync_broadcast_phase_event(
session.code,
"phase.question_shown",
{
"round_question_id": round_question.id,
"prompt": round_question.question.prompt,
"shown_at": round_question.shown_at.isoformat(),
"lie_deadline_at": lie_deadline_at.isoformat(),
"lie_seconds": round_config.lie_seconds,
},
_build_question_shown_payload(round_question, lie_deadline_iso, round_config.lie_seconds),
)
return JsonResponse(
{
"round_question": {
"id": round_question.id,
"prompt": round_question.question.prompt,
"round_number": round_question.round_number,
"shown_at": round_question.shown_at.isoformat(),
"lie_deadline_at": lie_deadline_at.isoformat(),
},
"config": {
"lie_seconds": round_config.lie_seconds,
},
},
_build_question_shown_response(round_question, lie_deadline_iso, round_config.lie_seconds),
status=201,
)