コード例 #1
0
ファイル: game.py プロジェクト: vu-cs3892-21s/Group7
def create_game_from_json(game_json: Json) -> str:

    # Create game and questions
    game: Game = Game(status='Created',
                      operations=','.join(game_json["operations"]),
                      mode=game_json["mode"],
                      question_type=game_json["questionType"],
                      num_questions=game_json["numberOfQuestions"],
                      duration=game_json["duration"])
    db.session.add(game)
    db.session.commit()

    questions: List[Tuple[str, str]] = create_questions(game_json)

    # Add questions to database
    for quest_num in range(game_json["numberOfQuestions"]):
        question, answer = questions[quest_num]
        game_question: GameQuestion = GameQuestion(game_id=game.id,
                                                   question=question,
                                                   answer=answer,
                                                   quest_num=1 + quest_num)
        db.session.add(game_question)
    db.session.commit()
    return str(game.id)