gsparc-mezzouna-api/app/routes/anomalies.py

35 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Routes — anomalies."""
from fastapi import APIRouter, Depends, Request, Form
from fastapi.responses import HTMLResponse, RedirectResponse
from app.auth import require_auth
from app.baserow import list_rows, update_row
from app.templates import templates
from app.config import TABLE_ANOMALIES, TABLE_VEHICULES
router = APIRouter(prefix="/anomalies")
@router.get("/", response_class=HTMLResponse)
async def liste_anomalies(request: Request, user=Depends(require_auth)):
anomalies = await list_rows(TABLE_ANOMALIES, size=100)
vehicules = await list_rows(TABLE_VEHICULES)
return templates.TemplateResponse("anomalies.html", {
"request": request,
"anomalies": anomalies,
"vehicules": {v["رقم_الماتريكول"]: v["النوع"] for v in vehicules},
})
@router.post("/{row_id}/resolve")
async def resoudre_anomalie(
request: Request,
row_id: int,
action: str = Form(""),
user=Depends(require_auth),
):
await update_row(TABLE_ANOMALIES, row_id, {
"تمت_المعالجة": True,
"إجراء_التصحيح": action,
})
return RedirectResponse(url="/anomalies", status_code=303)