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:
@@ -1,41 +1,57 @@
|
||||
# API Directory - Phase 1 Complete
|
||||
# GoMag Import Manager - FastAPI Application
|
||||
|
||||
## Core Files
|
||||
Admin interface si orchestrator pentru importul comenzilor GoMag in Oracle ROA.
|
||||
|
||||
### 🎛️ `admin.py`
|
||||
**Purpose:** Flask web admin interface pentru mapări SKU
|
||||
- Oracle connection pool management
|
||||
- CRUD operations pentru ARTICOLE_TERTI
|
||||
- Web interface pentru configurare mapări
|
||||
- **Port:** 5000 (configurable)
|
||||
## Componente
|
||||
|
||||
### 🧪 `tests/`
|
||||
**Purpose:** Directory cu toate testele și utilitățile validation
|
||||
- `final_validation.py` - Ultimate P1-004 validation script
|
||||
- `test_final_success.py` - Complete end-to-end test
|
||||
- `test_syntax.py` - Package compilation checker
|
||||
- `check_packages.py` - Package status utility
|
||||
- `check_table_structure.py` - Schema validation utility
|
||||
- `README.md` - Documentation pentru toate testele
|
||||
### Core
|
||||
- **main.py** - Entry point FastAPI, lifespan (Oracle pool + SQLite init), file logging
|
||||
- **config.py** - Settings via pydantic-settings (citeste .env)
|
||||
- **database.py** - Oracle connection pool + SQLite schema + helpers
|
||||
|
||||
## Configuration Files
|
||||
### Routers (HTTP Endpoints)
|
||||
| Router | Prefix | Descriere |
|
||||
|--------|--------|-----------|
|
||||
| health | /health, /api/health | Status Oracle + SQLite |
|
||||
| dashboard | / | Dashboard HTML cu stat cards |
|
||||
| mappings | /mappings, /api/mappings | CRUD ARTICOLE_TERTI + CSV |
|
||||
| articles | /api/articles | Cautare NOM_ARTICOLE |
|
||||
| validation | /api/validate | Scanare + validare SKU-uri |
|
||||
| sync | /sync, /api/sync | Import orchestration + scheduler |
|
||||
|
||||
### 📁 `database-scripts/`
|
||||
- `01_create_table.sql` - ARTICOLE_TERTI table
|
||||
- `02_import_parteneri.sql` - PACK_IMPORT_PARTENERI package
|
||||
- `04_import_comenzi.sql` - PACK_IMPORT_COMENZI package
|
||||
### Services (Business Logic)
|
||||
| Service | Rol |
|
||||
|---------|-----|
|
||||
| mapping_service | CRUD pe ARTICOLE_TERTI (Oracle) |
|
||||
| article_service | Cautare in NOM_ARTICOLE (Oracle) |
|
||||
| import_service | Port din VFP: partner/address/order creation |
|
||||
| sync_service | Orchestrare: read JSONs → validate → import → log |
|
||||
| validation_service | Batch-validare SKU-uri (chunks of 500) |
|
||||
| order_reader | Citire gomag_orders_page*.json din vfp/output/ |
|
||||
| sqlite_service | CRUD pe SQLite (sync_runs, import_orders, missing_skus) |
|
||||
| scheduler_service | APScheduler - sync periodic configurabil din UI |
|
||||
|
||||
### 🐳 `docker-compose.yaml`
|
||||
Oracle container orchestration
|
||||
## Rulare
|
||||
|
||||
### 🔧 `.env`
|
||||
Environment variables pentru MARIUSM_AUTO schema
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
uvicorn app.main:app --host 0.0.0.0 --port 5003 --reload
|
||||
```
|
||||
|
||||
### 📋 `requirements.txt`
|
||||
Python dependencies (oracledb, flask, etc.)
|
||||
## Testare
|
||||
|
||||
---
|
||||
```bash
|
||||
# Test A - fara Oracle (verifica importuri + rute)
|
||||
python test_app_basic.py
|
||||
|
||||
**Phase 1 Status:** ✅ 100% COMPLETE
|
||||
**Ready for:** Phase 2 VFP Integration
|
||||
**Cleanup Date:** 10 septembrie 2025, 12:57
|
||||
# Test C - cu Oracle (integrare completa)
|
||||
python test_integration.py
|
||||
```
|
||||
|
||||
## Dual Database
|
||||
- **Oracle** - date ERP (ARTICOLE_TERTI, NOM_ARTICOLE, COMENZI)
|
||||
- **SQLite** - tracking local (sync_runs, import_orders, missing_skus, scheduler_config)
|
||||
|
||||
## Logging
|
||||
Log files in `../logs/sync_comenzi_YYYYMMDD_HHMMSS.log`
|
||||
Format: `2026-03-11 14:30:25 | INFO | app.services.sync_service | mesaj`
|
||||
|
||||
Reference in New Issue
Block a user