✨ Added string-option to API
This commit is contained in:
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user