fix(gameplay): make scoreboard reads idempotent
This commit is contained in:
@@ -714,11 +714,12 @@ def reveal_scoreboard(request: HttpRequest, code: str) -> JsonResponse:
|
||||
|
||||
with transaction.atomic():
|
||||
locked_session = GameSession.objects.select_for_update().get(pk=session.pk)
|
||||
if locked_session.status != GameSession.Status.REVEAL:
|
||||
return JsonResponse({"error": "Scoreboard is only available in reveal phase"}, status=400)
|
||||
if locked_session.status not in {GameSession.Status.REVEAL, GameSession.Status.SCOREBOARD}:
|
||||
return JsonResponse({"error": "Scoreboard is only available in reveal/scoreboard phase"}, status=400)
|
||||
|
||||
locked_session.status = GameSession.Status.SCOREBOARD
|
||||
locked_session.save(update_fields=["status"])
|
||||
if locked_session.status == GameSession.Status.REVEAL:
|
||||
locked_session.status = GameSession.Status.SCOREBOARD
|
||||
locked_session.save(update_fields=["status"])
|
||||
|
||||
leaderboard = list(
|
||||
Player.objects.filter(session=session)
|
||||
|
||||
Reference in New Issue
Block a user