47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from models import QuizEntity, QuestionItemEntity, UserEntity
|
|
from schemas import QuizGetSchema, QuestionItemSchema
|
|
from schemas.response import RecomendationResponse
|
|
|
|
|
|
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:
|
|
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 []
|
|
],
|
|
)
|
|
|
|
|
|
def quiz_to_recomendation_mapper(
|
|
quiz_entity: QuizEntity,
|
|
user_entity: UserEntity,
|
|
) -> RecomendationResponse:
|
|
return RecomendationResponse(
|
|
quiz_id=str(quiz_entity.id),
|
|
author_id=str(user_entity.id),
|
|
author_name=user_entity.name,
|
|
title=quiz_entity.title,
|
|
description=quiz_entity.description,
|
|
date=quiz_entity.date.strftime("%d-%B-%Y"),
|
|
duration=quiz_entity.limit_duration,
|
|
total_quiz=quiz_entity.total_quiz,
|
|
)
|