feat: addiing get answer user in session
This commit is contained in:
parent
740748ed61
commit
ecf61c6c1d
|
@ -117,21 +117,33 @@ class AnswerService:
|
|||
if not answer_data:
|
||||
return None
|
||||
|
||||
quiz = self.quiz_repository.get_by_id(answer_data.quiz_id)
|
||||
question_listings = quiz.question_listings # List[QuestionItemEntity]
|
||||
|
||||
# Mapping question_index ke QuestionItemEntity
|
||||
question_map = {q.index: q for q in question_listings}
|
||||
|
||||
answers_data = []
|
||||
for ans in answer_data.answers:
|
||||
question_entity = question_map.get(ans.question_index)
|
||||
question_fields = question_entity.dict() if question_entity else {}
|
||||
|
||||
answers_data.append(
|
||||
{
|
||||
**question_fields, # Langsung unpack semua field QuestionItemEntity ke dalam dictionary
|
||||
"answer": ans.answer,
|
||||
"is_correct": ans.is_correct,
|
||||
"time_spent": ans.time_spent,
|
||||
}
|
||||
)
|
||||
|
||||
data = AnsweredQuizResponse(
|
||||
id=str(answer_data.id),
|
||||
session_id=answer_data.session_id,
|
||||
quiz_id=answer_data.quiz_id,
|
||||
user_id=answer_data.user_id,
|
||||
answered_at=DatetimeUtil.to_string(answer_data.answered_at),
|
||||
answers=[
|
||||
{
|
||||
"question_index": ans.question_index,
|
||||
"answer": ans.answer,
|
||||
"is_correct": ans.is_correct,
|
||||
"time_spent": ans.time_spent,
|
||||
}
|
||||
for ans in answer_data.answers
|
||||
],
|
||||
answers=answers_data,
|
||||
total_score=answer_data.total_score,
|
||||
total_correct=answer_data.total_correct,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue