Start integrating the onboarding flow with backend 3

This commit is contained in:
Urtzi Alfaro
2025-09-04 23:19:53 +02:00
parent 9eedc2e5f2
commit 0faaa25e58
26 changed files with 314 additions and 767 deletions

View File

@@ -11,7 +11,7 @@ from datetime import datetime
import structlog
from app.core.database import get_db
from shared.auth.decorators import get_current_user_dep, get_current_tenant_id_dep
from shared.auth.decorators import get_current_user_dep
router = APIRouter(tags=["sync"])
logger = structlog.get_logger()
@@ -22,15 +22,11 @@ async def trigger_sync(
sync_request: Dict[str, Any] = Body(...),
tenant_id: UUID = Path(..., description="Tenant ID"),
config_id: UUID = Path(..., description="Configuration ID"),
current_tenant: str = Depends(get_current_tenant_id_dep),
current_user: Dict[str, Any] = Depends(get_current_user_dep),
db=Depends(get_db)
):
"""Trigger manual synchronization with POS system"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
sync_type = sync_request.get("sync_type", "incremental") # full, incremental
data_types = sync_request.get("data_types", ["transactions"]) # transactions, products, customers
@@ -68,14 +64,10 @@ async def get_sync_status(
tenant_id: UUID = Path(..., description="Tenant ID"),
config_id: UUID = Path(..., description="Configuration ID"),
limit: int = Query(10, ge=1, le=100, description="Number of sync logs to return"),
current_tenant: str = Depends(get_current_tenant_id_dep),
db=Depends(get_db)
):
"""Get synchronization status and recent sync history"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
# TODO: Get sync status from database
# TODO: Get recent sync logs
@@ -107,14 +99,10 @@ async def get_sync_logs(
status: Optional[str] = Query(None, description="Filter by sync status"),
sync_type: Optional[str] = Query(None, description="Filter by sync type"),
data_type: Optional[str] = Query(None, description="Filter by data type"),
current_tenant: str = Depends(get_current_tenant_id_dep),
db=Depends(get_db)
):
"""Get detailed sync logs"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
# TODO: Implement log retrieval with filters
@@ -140,14 +128,10 @@ async def get_pos_transactions(
is_synced: Optional[bool] = Query(None, description="Filter by sync status"),
limit: int = Query(50, ge=1, le=200, description="Number of transactions to return"),
offset: int = Query(0, ge=0, description="Number of transactions to skip"),
current_tenant: str = Depends(get_current_tenant_id_dep),
db=Depends(get_db)
):
"""Get POS transactions for a tenant"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
# TODO: Implement transaction retrieval with filters
@@ -176,14 +160,10 @@ async def sync_single_transaction(
tenant_id: UUID = Path(..., description="Tenant ID"),
transaction_id: UUID = Path(..., description="Transaction ID"),
force: bool = Query(False, description="Force sync even if already synced"),
current_tenant: str = Depends(get_current_tenant_id_dep),
db=Depends(get_db)
):
"""Manually sync a single transaction to sales service"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
# TODO: Implement single transaction sync
@@ -204,14 +184,10 @@ async def sync_single_transaction(
async def get_sync_analytics(
tenant_id: UUID = Path(..., description="Tenant ID"),
days: int = Query(30, ge=1, le=365, description="Number of days to analyze"),
current_tenant: str = Depends(get_current_tenant_id_dep),
db=Depends(get_db)
):
"""Get sync performance analytics"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
# TODO: Implement analytics calculation
@@ -244,15 +220,11 @@ async def get_sync_analytics(
async def resync_failed_transactions(
tenant_id: UUID = Path(..., description="Tenant ID"),
days_back: int = Query(7, ge=1, le=90, description="How many days back to resync"),
current_tenant: str = Depends(get_current_tenant_id_dep),
current_user: Dict[str, Any] = Depends(get_current_user_dep),
db=Depends(get_db)
):
"""Resync failed transactions from the specified time period"""
try:
# Verify tenant access
if str(tenant_id) != current_tenant:
raise HTTPException(status_code=403, detail="Access denied to this tenant")
logger.info("Resync failed transactions requested",
tenant_id=tenant_id,