feat: add FastAPI admin dashboard with sync orchestration and test suite

Replace Flask admin with FastAPI app (api/app/) featuring:
- Dashboard with stat cards, sync control, and history
- Mappings CRUD for ARTICOLE_TERTI with CSV import/export
- Article autocomplete from NOM_ARTICOLE
- SKU pre-validation before import
- Sync orchestration: read JSONs -> validate -> import -> log to SQLite
- APScheduler for periodic sync from UI
- File logging to logs/sync_comenzi_YYYYMMDD_HHMMSS.log
- Oracle pool None guard (503 vs 500 on unavailable)

Test suite:
- test_app_basic.py: 30 tests (imports + routes) without Oracle
- test_integration.py: 9 integration tests with Oracle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 14:35:16 +02:00
parent 902f99c507
commit 9c42187f02
35 changed files with 3730 additions and 54 deletions

View File

@@ -6,13 +6,13 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
**System:** Import Comenzi Web → Sistem ROA Oracle
This is a multi-tier system that automatically imports orders from web platforms (GoMag, etc.) into the ROA Oracle ERP system. The project combines Oracle PL/SQL packages, Visual FoxPro orchestration, and a Flask web admin interface for SKU mapping management.
This is a multi-tier system that automatically imports orders from web platforms (GoMag, etc.) into the ROA Oracle ERP system. The project combines Oracle PL/SQL packages, Visual FoxPro orchestration, and a FastAPI web admin/dashboard interface.
**Current Status:** Phase 1 (Database Foundation) - 75% Complete
- ✅ P1-001: ARTICOLE_TERTI table created
- ✅ P1-002: IMPORT_PARTENERI package complete
- ✅ P1-003: IMPORT_COMENZI package complete
- 🔄 P1-004: Manual testing packages (NEXT UP)
**Current Status:** Phase 4 Complete, Phase 5 In Progress
- ✅ Phase 1: Database Foundation (ARTICOLE_TERTI, IMPORT_PARTENERI, IMPORT_COMENZI)
- ✅ Phase 2: VFP Integration (gomag-vending.prg, sync-comenzi-web.prg)
- ✅ Phase 3-4: FastAPI Admin + Dashboard (mappings CRUD, sync orchestration, pre-validation)
- 🔄 Phase 5: Production (file logging done, auth + notifications pending)
## Architecture
@@ -25,8 +25,8 @@ This is a multi-tier system that automatically imports orders from web platforms
### Tech Stack
- **Backend:** Oracle PL/SQL packages
- **Integration:** Visual FoxPro 9
- **Admin Interface:** Flask + Oracle connection pool
- **Data:** Oracle 11g/12c (ROA system)
- **Admin/Dashboard:** FastAPI + Jinja2 + Oracle pool + SQLite
- **Data:** Oracle 11g/12c (ROA system), SQLite (local tracking)
## Core Components
@@ -87,15 +87,18 @@ CREATE TABLE ARTICOLE_TERTI (
);
```
### Flask Admin Interface
### FastAPI Admin/Dashboard
#### admin.py
**Location:** `api/admin.py`
#### app/main.py
**Location:** `api/app/main.py`
**Features:**
- Oracle connection pool management
- SKU mappings CRUD operations
- Web interface for configuration
- Real-time validation
- FastAPI with lifespan (Oracle pool + SQLite init)
- File logging to `logs/sync_comenzi_YYYYMMDD_HHMMSS.log`
- Routers: health, dashboard, mappings, articles, validation, sync
- Services: mapping, article, import, sync, validation, order_reader, sqlite, scheduler
- Templates: Jinja2 (dashboard, mappings, sync_detail, missing_skus)
- Dual database: Oracle (ERP data) + SQLite (tracking)
- APScheduler for periodic sync
## Development Commands
@@ -115,10 +118,17 @@ sqlplus CONTAFIN_ORACLE/password@ROA_ROMFAST @03_import_comenzi.sql
DO vfp/gomag-vending.prg
```
### Flask Admin Interface
### FastAPI Admin/Dashboard
```bash
cd api
python admin.py
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 5003 --reload
```
### Testare
```bash
python api/test_app_basic.py # Test A - fara Oracle
python api/test_integration.py # Test C - cu Oracle
```
## Project Structure