From cfcc671545f9b8a310aeae9f8d97e130ef89e39d Mon Sep 17 00:00:00 2001 From: Mawoka Date: Thu, 14 Apr 2022 21:33:16 +0200 Subject: [PATCH] :bug: Players now can also start quizzes from others --- classquiz/routers/quiz.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index 0098e99..9ab5305 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -81,18 +81,17 @@ async def start_quiz(quiz_id: str, user: User = Depends(get_current_user)): 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"}) - else: - game_pin = randint(10000000, 99999999) - game = PlayGame( - quiz_id=quiz_id, - game_pin=str(game_pin), - questions=quiz.questions, - game_id=uuid.uuid4(), - title=quiz.title, - description=quiz.description, - ) - await redis.set(f"game:{str(game.game_pin)}", (game.json()), ex=18000) - return {**quiz.dict(exclude={"id"}), **game.dict(exclude={"questions"})} + game_pin = randint(10000000, 99999999) + game = PlayGame( + quiz_id=quiz_id, + game_pin=str(game_pin), + questions=quiz.questions, + game_id=uuid.uuid4(), + title=quiz.title, + description=quiz.description, + ) + await redis.set(f"game:{str(game.game_pin)}", (game.json()), ex=18000) + return {**quiz.dict(exclude={"id"}), **game.dict(exclude={"questions"})} @router.get("/join/{game_pin}")