♻️(summary) reorganize API code

I totally reorganized the API code, to gain in clarity.
This commit is contained in:
lebaudantoine
2024-11-30 00:17:12 +01:00
committed by aleb_the_flash
parent b12b14b277
commit 35741a1bc1
14 changed files with 83 additions and 49 deletions
+1
View File
@@ -0,0 +1 @@
"""Summary Api package."""
+17
View File
@@ -0,0 +1,17 @@
"""API routes related to application health checking."""
from fastapi import APIRouter
router = APIRouter()
@router.get("/__heartbeat__")
async def heartbeat():
"""Health check endpoint for monitoring."""
return
@router.get("/__lbheartbeat__")
async def lbheartbeat():
"""Health check endpoint for load balancer."""
return
+9
View File
@@ -0,0 +1,9 @@
"""API routes."""
from fastapi import APIRouter, Depends
from summary.api.route import tasks
from summary.core.security import verify_token
api_router = APIRouter(dependencies=[Depends(verify_token)])
api_router.include_router(tasks.router, tags=["tasks"])
@@ -0,0 +1 @@
"""Summary Api Route package."""
+34
View File
@@ -0,0 +1,34 @@
"""API routes related to application tasks."""
from celery.result import AsyncResult
from fastapi import APIRouter
from pydantic import BaseModel
from summary.core.celery_worker import process_audio_transcribe_summarize
class TaskCreation(BaseModel):
"""Task data."""
filename: str
email: str
sub: str
router = APIRouter(prefix="/tasks")
@router.post("/")
async def create_task(request: TaskCreation):
"""Create a task."""
task = process_audio_transcribe_summarize.delay(
request.filename, request.email, request.sub
)
return {"id": task.id, "message": "Task created"}
@router.get("/{task_id}")
async def get_task_status(task_id: str):
"""Check task status by ID."""
task = AsyncResult(task_id)
return {"id": task_id, "status": task.status}