from models import QuizEntity, QuestionItemEntity from schemas import QuizGetSchema, QuestionItemSchema def map_question_entity_to_schema(entity: QuestionItemEntity) -> QuestionItemSchema: return QuestionItemSchema( index=entity.index, question=entity.question, target_answer=entity.target_answer, duration=entity.duration, type=entity.type, options=entity.options, ) def map_quiz_entity_to_schema(entity: QuizEntity) -> QuizGetSchema: print(entity.id) return QuizGetSchema( id=str(entity.id), author_id=entity.author_id, title=entity.title, description=entity.description, is_public=entity.is_public, date=entity.date.strftime("%Y-%m-%d %H:%M:%S") if entity.date else None, total_quiz=entity.total_quiz or 0, limit_duration=entity.limit_duration or 0, question_listings=[ map_question_entity_to_schema(q) for q in entity.question_listings or [] ], )