Fastapi refactor update
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user