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,6 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .home import home_router
|
||||
from .listening import listening_router
|
||||
from .reading import reading_router
|
||||
from .speaking import speaking_router
|
||||
@@ -8,13 +7,22 @@ from .training import training_router
|
||||
from .writing import writing_router
|
||||
from .grade import grade_router
|
||||
from .user import user_router
|
||||
from .level import level_router
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(home_router, prefix="/api", tags=["Home"])
|
||||
router.include_router(listening_router, prefix="/api/listening", tags=["Listening"])
|
||||
router.include_router(reading_router, prefix="/api/reading", tags=["Reading"])
|
||||
router.include_router(speaking_router, prefix="/api/speaking", tags=["Speaking"])
|
||||
router.include_router(writing_router, prefix="/api/writing", tags=["Writing"])
|
||||
router.include_router(grade_router, prefix="/api/grade", tags=["Grade"])
|
||||
router.include_router(training_router, prefix="/api/training", tags=["Training"])
|
||||
router.include_router(user_router, prefix="/api/user", tags=["Users"])
|
||||
router = APIRouter(prefix="/api", tags=["Home"])
|
||||
|
||||
@router.get('/healthcheck')
|
||||
async def healthcheck():
|
||||
return {"healthy": True}
|
||||
|
||||
exercises_router = APIRouter()
|
||||
exercises_router.include_router(listening_router, prefix="/listening", tags=["Listening"])
|
||||
exercises_router.include_router(reading_router, prefix="/reading", tags=["Reading"])
|
||||
exercises_router.include_router(speaking_router, prefix="/speaking", tags=["Speaking"])
|
||||
exercises_router.include_router(writing_router, prefix="/writing", tags=["Writing"])
|
||||
exercises_router.include_router(level_router, prefix="/level", tags=["Level"])
|
||||
|
||||
router.include_router(grade_router, prefix="/grade", tags=["Grade"])
|
||||
router.include_router(training_router, prefix="/training", tags=["Training"])
|
||||
router.include_router(user_router, prefix="/user", tags=["Users"])
|
||||
router.include_router(exercises_router)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from dependency_injector.wiring import Provide, inject
|
||||
from fastapi import APIRouter, Depends, UploadFile, Request
|
||||
|
||||
from app.dtos.level import LevelExercisesDTO
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.controllers.abc import ILevelController
|
||||
|
||||
@@ -8,6 +9,17 @@ controller = "level_controller"
|
||||
level_router = APIRouter()
|
||||
|
||||
|
||||
@level_router.post(
|
||||
'/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_exercises(
|
||||
dto: LevelExercisesDTO,
|
||||
level_controller: ILevelController = Depends(Provide[controller])
|
||||
):
|
||||
return await level_controller.generate_exercises(dto)
|
||||
|
||||
@level_router.get(
|
||||
'/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
@@ -31,7 +43,7 @@ async def get_level_utas(
|
||||
|
||||
|
||||
@level_router.post(
|
||||
'/upload',
|
||||
'/import/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
@@ -43,7 +55,7 @@ async def upload(
|
||||
|
||||
|
||||
@level_router.post(
|
||||
'/custom',
|
||||
'/custom/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
import random
|
||||
|
||||
from dependency_injector.wiring import Provide, inject
|
||||
from fastapi import APIRouter, Depends, Path
|
||||
from fastapi import APIRouter, Depends, Path, Query
|
||||
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.controllers.abc import IListeningController
|
||||
from app.configs.constants import EducationalContent
|
||||
from app.dtos.listening import SaveListeningDTO
|
||||
|
||||
from app.configs.constants import EducationalContent, ListeningExerciseType
|
||||
from app.dtos.listening import SaveListeningDTO, GenerateListeningExercises
|
||||
|
||||
controller = "listening_controller"
|
||||
listening_router = APIRouter()
|
||||
|
||||
|
||||
@listening_router.get(
|
||||
'/section/{section}',
|
||||
'/{section}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_listening_question(
|
||||
exercises: list[str],
|
||||
async def generate_listening_dialog(
|
||||
section: int = Path(..., ge=1, le=4),
|
||||
topic: str | None = None,
|
||||
difficulty: str = random.choice(EducationalContent.DIFFICULTIES),
|
||||
difficulty: str = Query(default=None),
|
||||
topic: str = Query(default=None),
|
||||
listening_controller: IListeningController = Depends(Provide[controller])
|
||||
):
|
||||
return await listening_controller.get_listening_question(section, topic, exercises, difficulty)
|
||||
difficulty = random.choice(EducationalContent.DIFFICULTIES) if not difficulty else difficulty
|
||||
topic = random.choice(EducationalContent.TOPICS) if not topic else topic
|
||||
return await listening_controller.generate_listening_dialog(section, difficulty, topic)
|
||||
|
||||
@listening_router.post(
|
||||
'/{section}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_listening_exercise(
|
||||
dto: GenerateListeningExercises,
|
||||
section: int = Path(..., ge=1, le=4),
|
||||
listening_controller: IListeningController = Depends(Provide[controller])
|
||||
):
|
||||
return await listening_controller.get_listening_question(section, dto)
|
||||
|
||||
|
||||
@listening_router.post(
|
||||
|
||||
@@ -1,28 +1,51 @@
|
||||
import random
|
||||
from typing import Optional
|
||||
|
||||
from dependency_injector.wiring import Provide, inject
|
||||
from fastapi import APIRouter, Depends, Path, Query
|
||||
from fastapi import APIRouter, Depends, Path, Query, UploadFile
|
||||
|
||||
from app.dtos.reading import ReadingDTO
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.configs.constants import EducationalContent
|
||||
from app.controllers.abc import IReadingController
|
||||
|
||||
controller = "reading_controller"
|
||||
reading_router = APIRouter()
|
||||
|
||||
|
||||
@reading_router.get(
|
||||
'/passage/{passage}',
|
||||
@reading_router.post(
|
||||
'/import',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_reading_passage(
|
||||
passage: int = Path(..., ge=1, le=3),
|
||||
topic: str = Query(default=random.choice(EducationalContent.TOPICS)),
|
||||
exercises: list[str] = Query(default=[]),
|
||||
difficulty: str = Query(default=random.choice(EducationalContent.DIFFICULTIES)),
|
||||
async def upload(
|
||||
exercises: UploadFile,
|
||||
solutions: UploadFile = None,
|
||||
reading_controller: IReadingController = Depends(Provide[controller])
|
||||
):
|
||||
return await reading_controller.get_reading_passage(passage, topic, exercises, difficulty)
|
||||
print(exercises.filename)
|
||||
#print(solutions.filename)
|
||||
return await reading_controller.import_exam(exercises, solutions)
|
||||
|
||||
@reading_router.get(
|
||||
'/{passage}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_passage(
|
||||
topic: Optional[str] = Query(None),
|
||||
word_count: Optional[int] = Query(None),
|
||||
passage: int = Path(..., ge=1, le=3),
|
||||
reading_controller: IReadingController = Depends(Provide[controller])
|
||||
):
|
||||
return await reading_controller.generate_reading_passage(passage, topic, word_count)
|
||||
|
||||
@reading_router.post(
|
||||
'/{passage}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_reading(
|
||||
dto: ReadingDTO,
|
||||
passage: int = Path(..., ge=1, le=3),
|
||||
reading_controller: IReadingController = Depends(Provide[controller])
|
||||
):
|
||||
return await reading_controller.generate_reading_exercises(passage, dto)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import random
|
||||
from typing import Optional
|
||||
|
||||
from dependency_injector.wiring import inject, Provide
|
||||
from fastapi import APIRouter, Path, Query, Depends, BackgroundTasks
|
||||
|
||||
@@ -16,10 +16,12 @@ writing_router = APIRouter()
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_writing_task_general_question(
|
||||
async def generate_writing(
|
||||
task: int = Path(..., ge=1, le=2),
|
||||
topic: str = Query(default=random.choice(EducationalContent.MTI_TOPICS)),
|
||||
difficulty: str = Query(default=random.choice(EducationalContent.DIFFICULTIES)),
|
||||
difficulty: str = Query(default=None),
|
||||
topic: str = Query(default=None),
|
||||
writing_controller: IWritingController = Depends(Provide[controller])
|
||||
):
|
||||
difficulty = random.choice(EducationalContent.DIFFICULTIES) if not difficulty else difficulty
|
||||
topic = random.choice(EducationalContent.MTI_TOPICS) if not topic else topic
|
||||
return await writing_controller.get_writing_task_general_question(task, topic, difficulty)
|
||||
|
||||
Reference in New Issue
Block a user