From c5b5833384444d6a3823bfeb7a75fe62fed9e208 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Sun, 25 Sep 2022 15:26:36 +0200 Subject: [PATCH] :sparkles: Added string-option to API --- classquiz/routers/quiz.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index b730556..1ef73e7 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -257,11 +257,11 @@ async def export_quiz_answers(export_token: str, game_pin: str): class GetLiveDataResponse(BaseModel): quiz: PlayGame data: GameSession - player_count: int + player_count: int | str @router.get("/live", response_model=GetLiveDataResponse, tags=["live"]) -async def get_live_game_data(game_pin: int, api_key: str): +async def get_live_game_data(game_pin: int, api_key: str, player_count_as_a_string: bool = False): user_id = await check_api_key(api_key) redis_res = await redis.get(f"game:{game_pin}") if redis_res is None or user_id is None: @@ -279,7 +279,10 @@ async def get_live_game_data(game_pin: int, api_key: str): ga_1 = GameAnswer1(id=i, answers=[GameAnswer2.parse_obj(i) for i in res]) data.answers.append(ga_1) player_count = await redis.scard(f"game_session:{game_pin}:players") - return GetLiveDataResponse(quiz=game, data=data, player_count=player_count) + if player_count_as_a_string: + return GetLiveDataResponse(quiz=game, data=data, player_count=str(player_count)) + else: + return GetLiveDataResponse(quiz=game, data=data, player_count=player_count) @router.get("/live/user_count", tags=["live"])