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:
@@ -1,5 +1,5 @@
|
||||
from .exam import ExamMapper
|
||||
from .level import LevelMapper
|
||||
|
||||
__all__ = [
|
||||
"ExamMapper"
|
||||
"LevelMapper"
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import Dict, Any
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.dtos.exam import (
|
||||
from app.dtos.exams.level import (
|
||||
MultipleChoiceExercise,
|
||||
FillBlanksExercise,
|
||||
Part, Exam
|
||||
@@ -10,7 +10,7 @@ from app.dtos.exam import (
|
||||
from app.dtos.sheet import Sheet, Option, MultipleChoiceQuestion, FillBlanksWord
|
||||
|
||||
|
||||
class ExamMapper:
|
||||
class LevelMapper:
|
||||
|
||||
@staticmethod
|
||||
def map_to_exam_model(response: Dict[str, Any]) -> Exam:
|
||||
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