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,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)
|
||||
|
||||
Reference in New Issue
Block a user