Changes to endpoints so they allow to only get context and then the exercises as well as tidying up a bit
This commit is contained in:
39
app/mappers/reading.py
Normal file
39
app/mappers/reading.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from typing import Dict, Any
|
||||
|
||||
from app.dtos.exams.reading import (
|
||||
Part, Exam, Context, FillBlanksExercise,
|
||||
TrueFalseExercise, MatchSentencesExercise,
|
||||
WriteBlanksExercise
|
||||
)
|
||||
|
||||
|
||||
class ReadingMapper:
|
||||
|
||||
@staticmethod
|
||||
def map_to_exam_model(response: Dict[str, Any]) -> Exam:
|
||||
parts = []
|
||||
for part in response['parts']:
|
||||
part_exercises = part['exercises']
|
||||
context = Context(**part['text'])
|
||||
|
||||
model_map = {
|
||||
'fillBlanks': FillBlanksExercise,
|
||||
'trueFalse': TrueFalseExercise,
|
||||
'matchSentences': MatchSentencesExercise,
|
||||
'writeBlanks': WriteBlanksExercise
|
||||
}
|
||||
|
||||
exercises = []
|
||||
for exercise in part_exercises:
|
||||
exercise_type = exercise['type']
|
||||
exercises.append(model_map[exercise_type](**exercise))
|
||||
|
||||
part_kwargs = {
|
||||
"exercises": exercises,
|
||||
"text": context
|
||||
}
|
||||
|
||||
part_model = Part(**part_kwargs)
|
||||
parts.append(part_model)
|
||||
|
||||
return Exam(parts=parts, minTimer=response["minTimer"])
|
||||
Reference in New Issue
Block a user