Files
bakery-ia/services/pos/app/api/configurations.py

175 lines
6.0 KiB
Python
Raw Normal View History

2025-08-16 15:00:36 +02:00
"""
POS Configuration API Endpoints
2025-10-06 15:27:01 +02:00
ATOMIC layer - Basic CRUD operations for POS configurations
2025-08-16 15:00:36 +02:00
"""
from fastapi import APIRouter, Depends, HTTPException, Path, Query
from typing import List, Optional, Dict, Any
from uuid import UUID
import structlog
from app.core.database import get_db
from shared.auth.decorators import get_current_user_dep
2025-10-06 15:27:01 +02:00
from shared.auth.access_control import require_user_role, admin_role_required
from shared.routing import RouteBuilder
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
router = APIRouter()
2025-08-16 15:00:36 +02:00
logger = structlog.get_logger()
2025-10-06 15:27:01 +02:00
route_builder = RouteBuilder('pos')
@router.get(
route_builder.build_base_route("configurations"),
response_model=dict
)
@require_user_role(['viewer', 'member', 'admin', 'owner'])
async def list_pos_configurations(
tenant_id: UUID = Path(...),
pos_system: Optional[str] = Query(None),
is_active: Optional[bool] = Query(None),
current_user: dict = Depends(get_current_user_dep),
2025-08-16 15:00:36 +02:00
db=Depends(get_db)
):
2025-10-06 15:27:01 +02:00
"""List all POS configurations for a tenant"""
2025-08-16 15:00:36 +02:00
try:
return {
"configurations": [],
"total": 0,
"supported_systems": ["square", "toast", "lightspeed"]
}
except Exception as e:
2025-10-06 15:27:01 +02:00
logger.error("Failed to list POS configurations", error=str(e), tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to list configurations: {str(e)}")
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
@router.post(
route_builder.build_base_route("configurations"),
response_model=dict,
status_code=201
)
@admin_role_required
2025-08-16 15:00:36 +02:00
async def create_pos_configuration(
configuration_data: Dict[str, Any],
2025-10-06 15:27:01 +02:00
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
2025-08-16 15:00:36 +02:00
db=Depends(get_db)
):
2025-10-06 15:27:01 +02:00
"""Create a new POS configuration (Admin/Owner only)"""
2025-08-16 15:00:36 +02:00
try:
2025-10-06 15:27:01 +02:00
logger.info("Creating POS configuration",
2025-08-16 15:00:36 +02:00
tenant_id=tenant_id,
pos_system=configuration_data.get("pos_system"),
user_id=current_user.get("user_id"))
2025-10-06 15:27:01 +02:00
return {
"message": "POS configuration created successfully",
"id": "placeholder",
"pos_system": configuration_data.get("pos_system")
}
2025-08-16 15:00:36 +02:00
except Exception as e:
logger.error("Failed to create POS configuration", error=str(e), tenant_id=tenant_id)
2025-10-06 15:27:01 +02:00
raise HTTPException(status_code=500, detail=f"Failed to create configuration: {str(e)}")
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
@router.get(
route_builder.build_resource_detail_route("configurations", "config_id"),
response_model=dict
)
@require_user_role(['viewer', 'member', 'admin', 'owner'])
2025-08-16 15:00:36 +02:00
async def get_pos_configuration(
2025-10-06 15:27:01 +02:00
tenant_id: UUID = Path(...),
config_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
2025-08-16 15:00:36 +02:00
db=Depends(get_db)
):
"""Get a specific POS configuration"""
try:
2025-10-06 15:27:01 +02:00
return {
"id": str(config_id),
"tenant_id": str(tenant_id),
"pos_system": "square",
"is_active": True
}
2025-08-16 15:00:36 +02:00
except Exception as e:
2025-10-06 15:27:01 +02:00
logger.error("Failed to get POS configuration", error=str(e),
2025-08-16 15:00:36 +02:00
tenant_id=tenant_id, config_id=config_id)
2025-10-06 15:27:01 +02:00
raise HTTPException(status_code=500, detail=f"Failed to get configuration: {str(e)}")
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
@router.put(
route_builder.build_resource_detail_route("configurations", "config_id"),
response_model=dict
)
@admin_role_required
2025-08-16 15:00:36 +02:00
async def update_pos_configuration(
configuration_data: Dict[str, Any],
2025-10-06 15:27:01 +02:00
tenant_id: UUID = Path(...),
config_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
2025-08-16 15:00:36 +02:00
db=Depends(get_db)
):
2025-10-06 15:27:01 +02:00
"""Update a POS configuration (Admin/Owner only)"""
2025-08-16 15:00:36 +02:00
try:
2025-10-06 15:27:01 +02:00
return {"message": "Configuration updated successfully", "id": str(config_id)}
2025-08-16 15:00:36 +02:00
except Exception as e:
2025-10-06 15:27:01 +02:00
logger.error("Failed to update POS configuration", error=str(e),
2025-08-16 15:00:36 +02:00
tenant_id=tenant_id, config_id=config_id)
2025-10-06 15:27:01 +02:00
raise HTTPException(status_code=500, detail=f"Failed to update configuration: {str(e)}")
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
@router.delete(
route_builder.build_resource_detail_route("configurations", "config_id"),
response_model=dict
)
@require_user_role(['owner'])
2025-08-16 15:00:36 +02:00
async def delete_pos_configuration(
2025-10-06 15:27:01 +02:00
tenant_id: UUID = Path(...),
config_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
2025-08-16 15:00:36 +02:00
db=Depends(get_db)
):
2025-10-06 15:27:01 +02:00
"""Delete a POS configuration (Owner only)"""
2025-08-16 15:00:36 +02:00
try:
return {"message": "Configuration deleted successfully"}
except Exception as e:
2025-10-06 15:27:01 +02:00
logger.error("Failed to delete POS configuration", error=str(e),
2025-08-16 15:00:36 +02:00
tenant_id=tenant_id, config_id=config_id)
2025-10-06 15:27:01 +02:00
raise HTTPException(status_code=500, detail=f"Failed to delete configuration: {str(e)}")
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
# ============================================================================
# Reference Data
# ============================================================================
2025-08-16 15:00:36 +02:00
2025-10-06 15:27:01 +02:00
@router.get(
route_builder.build_global_route("supported-systems"),
response_model=dict
)
2025-08-16 15:00:36 +02:00
async def get_supported_pos_systems():
2025-10-06 15:27:01 +02:00
"""Get list of supported POS systems (no tenant context required)"""
2025-08-16 15:00:36 +02:00
return {
"systems": [
{
"id": "square",
"name": "Square POS",
"description": "Square Point of Sale system",
"features": ["payments", "inventory", "analytics", "webhooks"],
"supported_regions": ["US", "CA", "AU", "JP", "GB", "IE", "ES", "FR"]
},
{
"id": "toast",
"name": "Toast POS",
"description": "Toast restaurant POS system",
"features": ["orders", "payments", "menu_management", "webhooks"],
"supported_regions": ["US", "CA", "IE", "ES"]
},
{
"id": "lightspeed",
"name": "Lightspeed Restaurant",
"description": "Lightspeed restaurant management system",
"features": ["orders", "inventory", "reservations", "webhooks"],
"supported_regions": ["US", "CA", "EU", "AU"]
}
]
2025-10-06 15:27:01 +02:00
}