✨ 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):
|
class GetLiveDataResponse(BaseModel):
|
||||||
quiz: PlayGame
|
quiz: PlayGame
|
||||||
data: GameSession
|
data: GameSession
|
||||||
player_count: int
|
player_count: int | str
|
||||||
|
|
||||||
|
|
||||||
@router.get("/live", response_model=GetLiveDataResponse, tags=["live"])
|
@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)
|
user_id = await check_api_key(api_key)
|
||||||
redis_res = await redis.get(f"game:{game_pin}")
|
redis_res = await redis.get(f"game:{game_pin}")
|
||||||
if redis_res is None or user_id is None:
|
if redis_res is None or user_id is None:
|
||||||
@@ -279,6 +279,9 @@ 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])
|
ga_1 = GameAnswer1(id=i, answers=[GameAnswer2.parse_obj(i) for i in res])
|
||||||
data.answers.append(ga_1)
|
data.answers.append(ga_1)
|
||||||
player_count = await redis.scard(f"game_session:{game_pin}:players")
|
player_count = await redis.scard(f"game_session:{game_pin}:players")
|
||||||
|
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)
|
return GetLiveDataResponse(quiz=game, data=data, player_count=player_count)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user