diff --git a/backend/src/repository/question_repository.py b/backend/src/repository/question_repository.py index 69ca72c..e8ff743 100644 --- a/backend/src/repository/question_repository.py +++ b/backend/src/repository/question_repository.py @@ -14,13 +14,14 @@ class QuestionRepository(SQLAlchemyRepository): async def add_one(self, model: dict[str, typing.Any]) -> Question: async with async_session_maker() as session: - question_to_add = Question(type=model['type'], - question=model['question'], - task_id=model['task_id']) - possible_answers = [AnswerOption(**answer_option_schema, question_id=question_to_add.id) for - answer_option_schema in model['possible_answers']] - for ap in possible_answers: - question_to_add.possible_answers.append(ap) + possible_answers_list = model.pop('possible_answers') + question_to_add = Question(**model) + + possible_answers = [AnswerOption(**answer_option_dict, question_id=question_to_add.id) for + answer_option_dict in possible_answers_list] + for answer_option in possible_answers: + question_to_add.possible_answers.append(answer_option) + session.add(question_to_add) await session.commit() await session.refresh(question_to_add) diff --git a/backend/src/services/question_service.py b/backend/src/services/question_service.py index e198e0c..33c8328 100644 --- a/backend/src/services/question_service.py +++ b/backend/src/services/question_service.py @@ -11,7 +11,7 @@ def __init__(self, map_repo: type[AbstractRepository]): self.__question_repo = map_repo() async def create_one(self, task_id: uuid.UUID, schema_create: QuestionCreate) -> QuestionRead: - schema_dict = schema_create.model_dump() + schema_dict = schema_create.model_dump(include={'type', 'possible_answers', 'question'}) schema_dict['task_id'] = task_id return await self.__question_repo.add_one(schema_dict)