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:
Carlos-Mesquita
2024-11-04 23:31:48 +00:00
parent 2a032c5aba
commit 84ed2f2f6a
83 changed files with 4229 additions and 1843 deletions

View File

@@ -1,6 +1,8 @@
from fastapi import UploadFile
from typing import Dict
from watchfiles import awatch
from app.controllers.abc import ILevelController
from app.services.abc import ILevelService
@@ -10,6 +12,9 @@ class LevelController(ILevelController):
def __init__(self, level_service: ILevelService):
self._service = level_service
async def generate_exercises(self, dto):
return await self._service.generate_exercises(dto)
async def get_level_exam(self):
return await self._service.get_level_exam()

View File

@@ -1,7 +1,7 @@
from typing import List
from app.controllers.abc import IListeningController
from app.dtos.listening import SaveListeningDTO
from app.dtos.listening import SaveListeningDTO, GenerateListeningExercises
from app.services.abc import IListeningService
@@ -10,10 +10,11 @@ class ListeningController(IListeningController):
def __init__(self, listening_service: IListeningService):
self._service = listening_service
async def get_listening_question(
self, section_id: int, topic: str, req_exercises: List[str], difficulty: str
):
return await self._service.get_listening_question(section_id, topic, req_exercises, difficulty)
async def generate_listening_dialog(self, section_id: int, topic: str, difficulty: str):
return await self._service.generate_listening_dialog(section_id, topic, difficulty)
async def get_listening_question(self, section: int, dto: GenerateListeningExercises):
return await self._service.get_listening_question(section, dto)
async def save_listening(self, data: SaveListeningDTO):
return await self._service.save_listening(data.parts, data.minTimer, data.difficulty, data.id)

View File

@@ -1,11 +1,12 @@
import random
import logging
from typing import List
from typing import Optional
from fastapi import UploadFile
from grpc import services
from app.controllers.abc import IReadingController
from app.dtos.reading import ReadingDTO
from app.services.abc import IReadingService
from app.configs.constants import FieldsAndExercises
from app.helpers import ExercisesHelper
class ReadingController(IReadingController):
@@ -13,31 +14,12 @@ class ReadingController(IReadingController):
def __init__(self, reading_service: IReadingService):
self._service = reading_service
self._logger = logging.getLogger(__name__)
self._passages = {
"passage_1": {
"start_id": 1,
"total_exercises": FieldsAndExercises.TOTAL_READING_PASSAGE_1_EXERCISES
},
"passage_2": {
"start_id": 14,
"total_exercises": FieldsAndExercises.TOTAL_READING_PASSAGE_2_EXERCISES
},
"passage_3": {
"start_id": 27,
"total_exercises": FieldsAndExercises.TOTAL_READING_PASSAGE_3_EXERCISES
}
}
async def get_reading_passage(self, passage_id: int, topic: str, req_exercises: List[str], difficulty: str):
passage = self._passages[f'passage_{str(passage_id)}']
async def import_exam(self, exercises: UploadFile, solutions: UploadFile = None):
return await self._service.import_exam(exercises, solutions)
if len(req_exercises) == 0:
req_exercises = random.sample(FieldsAndExercises.READING_EXERCISE_TYPES, 2)
async def generate_reading_passage(self, passage: int, topic: Optional[str], word_count: Optional[int]):
return await self._service.generate_reading_passage(passage, topic, word_count)
number_of_exercises_q = ExercisesHelper.divide_number_into_parts(
passage["total_exercises"], len(req_exercises)
)
return await self._service.gen_reading_passage(
passage_id, topic, req_exercises, number_of_exercises_q, difficulty, passage["start_id"]
)
async def generate_reading_exercises(self, passage: int, dto: ReadingDTO):
return await self._service.generate_reading_exercises(dto)