🐛 Players now can also start quizzes from others
This commit is contained in:
+11
-12
@@ -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)
|
quiz = await Quiz.objects.get_or_none(id=quiz_id, public=True)
|
||||||
if quiz is None:
|
if quiz is None:
|
||||||
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
|
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
|
||||||
else:
|
game_pin = randint(10000000, 99999999)
|
||||||
game_pin = randint(10000000, 99999999)
|
game = PlayGame(
|
||||||
game = PlayGame(
|
quiz_id=quiz_id,
|
||||||
quiz_id=quiz_id,
|
game_pin=str(game_pin),
|
||||||
game_pin=str(game_pin),
|
questions=quiz.questions,
|
||||||
questions=quiz.questions,
|
game_id=uuid.uuid4(),
|
||||||
game_id=uuid.uuid4(),
|
title=quiz.title,
|
||||||
title=quiz.title,
|
description=quiz.description,
|
||||||
description=quiz.description,
|
)
|
||||||
)
|
await redis.set(f"game:{str(game.game_pin)}", (game.json()), ex=18000)
|
||||||
await redis.set(f"game:{str(game.game_pin)}", (game.json()), ex=18000)
|
return {**quiz.dict(exclude={"id"}), **game.dict(exclude={"questions"})}
|
||||||
return {**quiz.dict(exclude={"id"}), **game.dict(exclude={"questions"})}
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/join/{game_pin}")
|
@router.get("/join/{game_pin}")
|
||||||
|
|||||||
Reference in New Issue
Block a user