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

106 lines
3.3 KiB
Python

# services/inventory/app/main.py
"""
Inventory Service FastAPI Application
"""
import os
from fastapi import FastAPI
# Import core modules
from app.core.config import settings
from app.core.database import database_manager
from app.api import ingredients, stock, classification, transformations
from app.services.inventory_alert_service import InventoryAlertService
from shared.service_base import StandardFastAPIService
# Import enhanced routers
from app.api.dashboard import router as dashboard_router
from app.api.food_safety import router as food_safety_router
class InventoryService(StandardFastAPIService):
"""Inventory Service with standardized setup"""
def __init__(self):
# Define expected database tables for health checks
inventory_expected_tables = [
'ingredients', 'stock', 'stock_movements', 'product_transformations',
'stock_alerts', 'food_safety_compliance', 'temperature_logs', 'food_safety_alerts'
]
super().__init__(
service_name="inventory-service",
app_name=settings.APP_NAME,
description=settings.DESCRIPTION,
version=settings.VERSION,
log_level=settings.LOG_LEVEL,
cors_origins=settings.CORS_ORIGINS,
api_prefix=settings.API_V1_STR,
database_manager=database_manager,
expected_tables=inventory_expected_tables
)
async def on_startup(self, app: FastAPI):
"""Custom startup logic for inventory service"""
# Initialize alert service
alert_service = InventoryAlertService(settings)
await alert_service.start()
self.logger.info("Inventory alert service started")
# Store alert service in app state
app.state.alert_service = alert_service
async def on_shutdown(self, app: FastAPI):
"""Custom shutdown logic for inventory service"""
# Stop alert service
if hasattr(app.state, 'alert_service'):
await app.state.alert_service.stop()
self.logger.info("Alert service stopped")
def get_service_features(self):
"""Return inventory-specific features"""
return [
"ingredient_management",
"stock_tracking",
"expiration_alerts",
"low_stock_alerts",
"batch_tracking",
"fifo_consumption",
"barcode_support",
"food_safety_compliance",
"temperature_monitoring",
"dashboard_analytics",
"business_model_detection",
"real_time_alerts",
"regulatory_reporting"
]
# Create service instance
service = InventoryService()
# Create FastAPI app with standardized setup
app = service.create_app()
# Setup standard endpoints
service.setup_standard_endpoints()
# Include routers using the service helper
service.add_router(ingredients.router)
service.add_router(stock.router)
service.add_router(transformations.router)
service.add_router(classification.router)
service.add_router(dashboard_router)
service.add_router(food_safety_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"
)