From c1f1a1721a4c3fd00cf215922f7ef827f3d8a2ad Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 5 Oct 2022 11:30:48 +0530 Subject: [PATCH 1/3] fix: create a new game pin if there already exists one Signed-off-by: Pranav --- classquiz/routers/quiz.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index 24dd009..b9f30ee 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -107,6 +107,11 @@ async def start_quiz( game_pin = randint(10000000, 99999999) if custom_field == "": custom_field = None + game = await redis.get(f"game:{game_pin}") + while( game is not None): + game_pin = randint(10000000, 99999999) + game = await redis.get(f"game:{game_pin}") + game = PlayGame( quiz_id=quiz_id, game_pin=str(game_pin), From c1df8f37c27ac8189ae333eef03211b85509ba87 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Oct 2022 06:14:16 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- classquiz/routers/quiz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index b9f30ee..d6d128d 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -108,10 +108,10 @@ async def start_quiz( if custom_field == "": custom_field = None game = await redis.get(f"game:{game_pin}") - while( game is not None): + while game is not None: game_pin = randint(10000000, 99999999) game = await redis.get(f"game:{game_pin}") - + game = PlayGame( quiz_id=quiz_id, game_pin=str(game_pin), From 51fc1aa8b7ca9fdb02e5228192dae3d57c5c41d8 Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 5 Oct 2022 13:05:01 +0530 Subject: [PATCH 3/3] chore: reduce game pin to 6 digits Signed-off-by: Pranav --- classquiz/routers/quiz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index d6d128d..89e4b59 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -104,12 +104,12 @@ async def start_quiz( quiz = await Quiz.objects.get_or_none(id=quiz_id, public=True) if quiz is None: return JSONResponse(status_code=404, content={"detail": "quiz not found"}) - game_pin = randint(10000000, 99999999) + game_pin = randint(100000, 999999) if custom_field == "": custom_field = None game = await redis.get(f"game:{game_pin}") while game is not None: - game_pin = randint(10000000, 99999999) + game_pin = randint(100000, 999999) game = await redis.get(f"game:{game_pin}") game = PlayGame(