29 lines
972 B
Python
29 lines
972 B
Python
import random
|
|
|
|
from dependency_injector.wiring import Provide, inject
|
|
from fastapi import APIRouter, Depends, Path, Query
|
|
|
|
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}',
|
|
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)),
|
|
reading_controller: IReadingController = Depends(Provide[controller])
|
|
):
|
|
return await reading_controller.get_reading_passage(passage, topic, exercises, difficulty)
|
|
|
|
|