Files
bakery-ia/services/suppliers/app/main.py
2025-09-29 13:13:12 +02:00

98 lines
3.0 KiB
Python

# services/suppliers/app/main.py
"""
Supplier & Procurement Service FastAPI Application
"""
import os
from fastapi import FastAPI
from app.core.config import settings
from app.core.database import database_manager
from app.api import suppliers, purchase_orders, deliveries
from shared.service_base import StandardFastAPIService
# Include enhanced performance tracking router
from app.api.performance import router as performance_router
class SuppliersService(StandardFastAPIService):
"""Suppliers Service with standardized setup"""
def __init__(self):
# Define expected database tables for health checks
suppliers_expected_tables = [
'suppliers', 'supplier_price_lists', 'purchase_orders', 'purchase_order_items',
'deliveries', 'delivery_items', 'supplier_quality_reviews', 'supplier_invoices',
'supplier_performance_metrics', 'supplier_alerts', 'supplier_scorecards',
'supplier_benchmarks', 'alert_rules'
]
super().__init__(
service_name="suppliers-service",
app_name=settings.APP_NAME,
description=settings.DESCRIPTION,
version=settings.VERSION,
cors_origins=settings.CORS_ORIGINS,
api_prefix=settings.API_V1_STR,
database_manager=database_manager,
expected_tables=suppliers_expected_tables
)
async def on_startup(self, app: FastAPI):
"""Custom startup logic for suppliers service"""
# Custom startup completed
pass
async def on_shutdown(self, app: FastAPI):
"""Custom shutdown logic for suppliers service"""
# Database cleanup is handled by the base class
pass
def get_service_features(self):
"""Return suppliers-specific features"""
return [
"supplier_management",
"vendor_onboarding",
"purchase_orders",
"delivery_tracking",
"quality_reviews",
"price_list_management",
"invoice_tracking",
"supplier_ratings",
"procurement_workflow",
"performance_tracking",
"performance_analytics",
"supplier_scorecards",
"performance_alerts",
"business_model_detection",
"dashboard_analytics",
"cost_optimization",
"risk_assessment",
"benchmarking"
]
# Create service instance
service = SuppliersService()
# Create FastAPI app with standardized setup
app = service.create_app()
# Setup standard endpoints
service.setup_standard_endpoints()
# Include routers
service.add_router(suppliers.router)
service.add_router(purchase_orders.router)
service.add_router(deliveries.router)
service.add_router(performance_router)
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"app.main:app",
host="0.0.0.0",
port=8000,
reload=os.getenv("RELOAD", "false").lower() == "true",
log_level="info"
)