43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import random
|
|
|
|
from dependency_injector.wiring import inject, Provide
|
|
from fastapi import APIRouter, Path, Query, Depends, UploadFile, File
|
|
|
|
from ielts_be.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
|
from ielts_be.configs.constants import EducationalContent
|
|
from ielts_be.controllers import IWritingController
|
|
|
|
controller = "writing_controller"
|
|
writing_router = APIRouter()
|
|
|
|
|
|
@writing_router.post(
|
|
'/{task}/attachment',
|
|
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
|
)
|
|
@inject
|
|
async def generate_writing_academic(
|
|
task: int = Path(..., ge=1, le=2),
|
|
file: UploadFile = File(...),
|
|
difficulty: str = Query(default=None),
|
|
writing_controller: IWritingController = Depends(Provide[controller])
|
|
):
|
|
difficulty = random.choice(EducationalContent.DIFFICULTIES) if not difficulty else difficulty
|
|
return await writing_controller.get_writing_task_academic_question(task, file, difficulty)
|
|
|
|
|
|
@writing_router.get(
|
|
'/{task}',
|
|
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
|
)
|
|
@inject
|
|
async def generate_writing(
|
|
task: int = Path(..., ge=1, le=2),
|
|
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)
|