feat: schelet gateway FastAPI (API v1 + worker + dashboard + SQLite WAL)
Structura repo conform plan.md sect. 4, booteaza cu /healthz verde:
- app/main.py: FastAPI (lifespan init_db), /healthz (worker viu + last login + queue), /metrics
- app/api/v1: POST /v1/prezentari (enqueue + dedup idempotency UNIQUE), GET prezentari/{id}, nomenclator, mapari
- app/rar_client.py: client RAR real (login/JWT, nomenclator, postPrezentare, getFinalizate) cu User-Agent obligatoriu (fix WAF 403)
- app/worker: proces separat, claim atomic BEGIN IMMEDIATE, heartbeat, login+send (send dezactivat by default)
- app/web: dashboard Jinja2+HTMX (coada, banner alerta blocate, worker viu/mort, stari empty)
- app/db.py + schema.sql: SQLite WAL, tabele accounts/api_keys/operations_mapping/nomenclator_rar/submissions/worker_heartbeat
- app/idempotency.py + payload.py: hash continut canonic + builder payload (status FINALIZATA, fara tipPrestatie)
- Dockerfile + docker-compose.yml (api+worker, volum SQLite persistent, restart:always)
- tools/import_dbf.py: stub T5
Verificat live: login prin rar_client OK (token 259), nomenclator 18 coduri, worker heartbeat -> /healthz worker_alive=True.
Ramas: T3 validare Pydantic, T4 snapshot payload, T2 reconciliere/retry worker, T5 import DBF, auth API-key, middleware redactare creds, criptare PII.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
41
app/payload.py
Normal file
41
app/payload.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""Constructor payload postPrezentare (schelet — T4 il completeaza).
|
||||
|
||||
Reguli din contract (docs/api-rar-contract.md):
|
||||
- status mereu "FINALIZATA".
|
||||
- tipPrestatie NU se trimite (server-generated GENERIC).
|
||||
- odometruFinal ca string.
|
||||
- sistemReparat trimis mereu (default "null").
|
||||
- prestatii: [{codPrestatie, idPrezentare: null}].
|
||||
- b64Image / odometruInitial optionale (se omit daca lipsesc).
|
||||
T4 adauga snapshot-test fata de exemplul oficial din contract.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def build_rar_payload(prezentare: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Mapeaza o prezentare interna -> payload exact pentru RAR postPrezentare."""
|
||||
prestatii = prezentare.get("prestatii") or []
|
||||
payload: dict[str, Any] = {
|
||||
"vin": (prezentare.get("vin") or "").strip().upper(),
|
||||
"nrInmatriculare": (prezentare.get("nr_inmatriculare") or "").strip().upper(),
|
||||
"dataPrestatie": prezentare.get("data_prestatie"),
|
||||
"odometruFinal": str(prezentare.get("odometru_final") or "").strip(),
|
||||
"odometruInitial": prezentare.get("odometru_initial"),
|
||||
"prestatii": [
|
||||
{
|
||||
"codPrestatie": (p.get("cod_prestatie") if isinstance(p, dict) else getattr(p, "cod_prestatie", None)),
|
||||
"idPrezentare": None,
|
||||
}
|
||||
for p in prestatii
|
||||
],
|
||||
"sistemReparat": prezentare.get("sistem_reparat") or "null",
|
||||
"status": "FINALIZATA",
|
||||
}
|
||||
if prezentare.get("obs"):
|
||||
payload["obs"] = prezentare["obs"]
|
||||
if prezentare.get("b64_image"):
|
||||
payload["b64Image"] = prezentare["b64_image"]
|
||||
return payload
|
||||
Reference in New Issue
Block a user