Async release
This commit is contained in:
18
app/api/__init__.py
Normal file
18
app/api/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .home import home_router
|
||||
from .listening import listening_router
|
||||
from .reading import reading_router
|
||||
from .speaking import speaking_router
|
||||
from .training import training_router
|
||||
from .writing import writing_router
|
||||
from .grade import grade_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"])
|
||||
49
app/api/grade.py
Normal file
49
app/api/grade.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from dependency_injector.wiring import inject, Provide
|
||||
from fastapi import APIRouter, Depends, Path, Request
|
||||
|
||||
from app.controllers.abc import IGradeController
|
||||
from app.dtos import WritingGradeTaskDTO
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
|
||||
controller = "grade_controller"
|
||||
grade_router = APIRouter()
|
||||
|
||||
|
||||
@grade_router.post(
|
||||
'/writing/{task}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def grade_writing_task(
|
||||
data: WritingGradeTaskDTO,
|
||||
task: int = Path(..., ge=1, le=2),
|
||||
grade_controller: IGradeController = Depends(Provide[controller])
|
||||
):
|
||||
return await grade_controller.grade_writing_task(task, data)
|
||||
|
||||
|
||||
@grade_router.post(
|
||||
'/speaking/{task}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def grade_speaking_task(
|
||||
request: Request,
|
||||
task: int = Path(..., ge=1, le=3),
|
||||
grade_controller: IGradeController = Depends(Provide[controller])
|
||||
):
|
||||
data = await request.json()
|
||||
return await grade_controller.grade_speaking_task(task, data)
|
||||
|
||||
|
||||
@grade_router.post(
|
||||
'/summary',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def grading_summary(
|
||||
request: Request,
|
||||
grade_controller: IGradeController = Depends(Provide[controller])
|
||||
):
|
||||
data = await request.json()
|
||||
return await grade_controller.grading_summary(data)
|
||||
9
app/api/home.py
Normal file
9
app/api/home.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
home_router = APIRouter()
|
||||
|
||||
|
||||
@home_router.get(
|
||||
'/healthcheck'
|
||||
)
|
||||
async def healthcheck():
|
||||
return {"healthy": True}
|
||||
30
app/api/level.py
Normal file
30
app/api/level.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from dependency_injector.wiring import Provide, inject
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.controllers.abc import ILevelController
|
||||
|
||||
controller = "level_controller"
|
||||
level_router = APIRouter()
|
||||
|
||||
|
||||
@level_router.get(
|
||||
'/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_level_exam(
|
||||
level_controller: ILevelController = Depends(Provide[controller])
|
||||
):
|
||||
return await level_controller.get_level_exam()
|
||||
|
||||
|
||||
@level_router.get(
|
||||
'/utas',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_level_utas(
|
||||
level_controller: ILevelController = Depends(Provide[controller])
|
||||
):
|
||||
return await level_controller.get_level_exam()
|
||||
40
app/api/listening.py
Normal file
40
app/api/listening.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import random
|
||||
|
||||
from dependency_injector.wiring import Provide, inject
|
||||
from fastapi import APIRouter, Depends, Path
|
||||
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.controllers.abc import IListeningController
|
||||
from app.configs.constants import EducationalContent
|
||||
from app.dtos import SaveListeningDTO
|
||||
|
||||
|
||||
controller = "listening_controller"
|
||||
listening_router = APIRouter()
|
||||
|
||||
|
||||
@listening_router.get(
|
||||
'/section/{section}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_listening_question(
|
||||
exercises: list[str],
|
||||
section: int = Path(..., ge=1, le=4),
|
||||
topic: str | None = None,
|
||||
difficulty: str = random.choice(EducationalContent.DIFFICULTIES),
|
||||
listening_controller: IListeningController = Depends(Provide[controller])
|
||||
):
|
||||
return await listening_controller.get_listening_question(section, topic, exercises, difficulty)
|
||||
|
||||
|
||||
@listening_router.post(
|
||||
'/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def save_listening(
|
||||
data: SaveListeningDTO,
|
||||
listening_controller: IListeningController = Depends(Provide[controller])
|
||||
):
|
||||
return await listening_controller.save_listening(data)
|
||||
28
app/api/reading.py
Normal file
28
app/api/reading.py
Normal file
@@ -0,0 +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)
|
||||
|
||||
|
||||
63
app/api/speaking.py
Normal file
63
app/api/speaking.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import random
|
||||
|
||||
from dependency_injector.wiring import inject, Provide
|
||||
from fastapi import APIRouter, Path, Query, Depends, BackgroundTasks
|
||||
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.configs.constants import EducationalContent
|
||||
from app.controllers.abc import ISpeakingController
|
||||
from app.dtos import SaveSpeakingDTO, SpeakingGenerateVideoDTO, SpeakingGenerateInteractiveVideoDTO
|
||||
|
||||
controller = "speaking_controller"
|
||||
speaking_router = APIRouter()
|
||||
|
||||
|
||||
@speaking_router.get(
|
||||
'/{task}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_speaking_task(
|
||||
task: int = Path(..., ge=1, le=3),
|
||||
topic: str = Query(default=random.choice(EducationalContent.MTI_TOPICS)),
|
||||
difficulty: str = Query(default=random.choice(EducationalContent.DIFFICULTIES)),
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.get_speaking_task(task, topic, difficulty)
|
||||
|
||||
|
||||
@speaking_router.post(
|
||||
'/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def save_speaking(
|
||||
data: SaveSpeakingDTO,
|
||||
background_tasks: BackgroundTasks,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.save_speaking(data, background_tasks)
|
||||
|
||||
|
||||
@speaking_router.post(
|
||||
'/generate_speaking_video',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_speaking_video(
|
||||
data: SpeakingGenerateVideoDTO,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.generate_speaking_video(data)
|
||||
|
||||
|
||||
@speaking_router.post(
|
||||
'/generate_interactive_video',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_interactive_video(
|
||||
data: SpeakingGenerateInteractiveVideoDTO,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.generate_interactive_video(data)
|
||||
21
app/api/training.py
Normal file
21
app/api/training.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from dependency_injector.wiring import Provide, inject
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from app.dtos import TipsDTO
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.controllers.abc import ITrainingController
|
||||
|
||||
controller = "training_controller"
|
||||
training_router = APIRouter()
|
||||
|
||||
|
||||
@training_router.post(
|
||||
'/tips',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_reading_passage(
|
||||
data: TipsDTO,
|
||||
training_controller: ITrainingController = Depends(Provide[controller])
|
||||
):
|
||||
return await training_controller.fetch_tips(data)
|
||||
25
app/api/writing.py
Normal file
25
app/api/writing.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import random
|
||||
|
||||
from dependency_injector.wiring import inject, Provide
|
||||
from fastapi import APIRouter, Path, Query, Depends
|
||||
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.configs.constants import EducationalContent
|
||||
from app.controllers.abc import IWritingController
|
||||
|
||||
controller = "writing_controller"
|
||||
writing_router = APIRouter()
|
||||
|
||||
|
||||
@writing_router.get(
|
||||
'/{task}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_writing_task_general_question(
|
||||
task: int = Path(..., ge=1, le=2),
|
||||
topic: str = Query(default=random.choice(EducationalContent.MTI_TOPICS)),
|
||||
difficulty: str = Query(default=random.choice(EducationalContent.DIFFICULTIES)),
|
||||
writing_controller: IWritingController = Depends(Provide[controller])
|
||||
):
|
||||
return await writing_controller.get_writing_task_general_question(task, topic, difficulty)
|
||||
Reference in New Issue
Block a user