🚑 Fixed live-API
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import json
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, validator
|
||||
from classquiz.config import settings, redis
|
||||
from classquiz.db.models import (
|
||||
PlayGame,
|
||||
@@ -38,6 +38,17 @@ class _ABCDQuizAnswer(ABCDQuizAnswer):
|
||||
class _QuizQuestion(QuizQuestion):
|
||||
answers: list[ABCDQuizAnswer] | RangeQuizAnswer | list[VotingQuizAnswer]
|
||||
|
||||
@validator("answers")
|
||||
def answers_not_none_if_abcd_type(cls, v, values):
|
||||
if values["type"] == QuizQuestionType.ABCD and type(v[0]) != _ABCDQuizAnswer:
|
||||
print(type(v[0]))
|
||||
raise ValueError("Answers can't be none if type is ABCD")
|
||||
if values["type"] == QuizQuestionType.RANGE and type(v) != RangeQuizAnswer:
|
||||
raise ValueError("Answer must be from type RangeQuizAnswer if type is RANGE")
|
||||
if values["type"] == QuizQuestionType.VOTING and type(v[0]) != VotingQuizAnswer:
|
||||
raise ValueError("Answer must be from type VotingQuizAnswer if type is VOTING")
|
||||
return v
|
||||
|
||||
|
||||
class _GetLivePlayGame(PlayGame):
|
||||
questions: list[_QuizQuestion]
|
||||
|
||||
@@ -107,9 +107,9 @@ async def join_game(sid: str, data: dict):
|
||||
await redis.sadd(f"game_session:{data.game_pin}:players", GamePlayer(username=data.username, sid=sid).json())
|
||||
if data.custom_field == "":
|
||||
data.custom_field = None
|
||||
print(data.custom_field)
|
||||
if data.custom_field is not None:
|
||||
await redis.hset(f"game:{data.game_pin}:player:custom_fields", data.username, data.custom_field)
|
||||
await redis.hset(f"game:{data.game_pin}:players:custom_fields", data.username, data.custom_field)
|
||||
|
||||
# await redis.set(
|
||||
# f"game_session:{data.game_pin}",
|
||||
# GameSession(admin=redis_res.admin, game_id=redis_res.game_id, answers=[]).json(),
|
||||
|
||||
Reference in New Issue
Block a user