REFACTOR ALL APIs
This commit is contained in:
82
services/pos/app/api/transactions.py
Normal file
82
services/pos/app/api/transactions.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
POS Transactions API Endpoints
|
||||
ATOMIC layer - Basic CRUD operations for POS transactions
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Path, Query
|
||||
from typing import Optional, Dict, Any
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
import structlog
|
||||
|
||||
from app.core.database import get_db
|
||||
from shared.auth.decorators import get_current_user_dep
|
||||
from shared.auth.access_control import require_user_role
|
||||
from shared.routing import RouteBuilder
|
||||
|
||||
router = APIRouter()
|
||||
logger = structlog.get_logger()
|
||||
route_builder = RouteBuilder('pos')
|
||||
|
||||
|
||||
@router.get(
|
||||
route_builder.build_base_route("transactions"),
|
||||
response_model=dict
|
||||
)
|
||||
@require_user_role(['viewer', 'member', 'admin', 'owner'])
|
||||
async def list_pos_transactions(
|
||||
tenant_id: UUID = Path(...),
|
||||
pos_system: Optional[str] = Query(None),
|
||||
start_date: Optional[datetime] = Query(None),
|
||||
end_date: Optional[datetime] = Query(None),
|
||||
status: Optional[str] = Query(None),
|
||||
is_synced: Optional[bool] = Query(None),
|
||||
limit: int = Query(50, ge=1, le=200),
|
||||
offset: int = Query(0, ge=0),
|
||||
current_user: dict = Depends(get_current_user_dep),
|
||||
db=Depends(get_db)
|
||||
):
|
||||
"""List POS transactions for a tenant"""
|
||||
try:
|
||||
return {
|
||||
"transactions": [],
|
||||
"total": 0,
|
||||
"has_more": False,
|
||||
"summary": {
|
||||
"total_amount": 0,
|
||||
"transaction_count": 0,
|
||||
"sync_status": {
|
||||
"synced": 0,
|
||||
"pending": 0,
|
||||
"failed": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error("Failed to list POS transactions", error=str(e), tenant_id=tenant_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to list transactions: {str(e)}")
|
||||
|
||||
|
||||
@router.get(
|
||||
route_builder.build_resource_detail_route("transactions", "transaction_id"),
|
||||
response_model=dict
|
||||
)
|
||||
@require_user_role(['viewer', 'member', 'admin', 'owner'])
|
||||
async def get_pos_transaction(
|
||||
tenant_id: UUID = Path(...),
|
||||
transaction_id: UUID = Path(...),
|
||||
current_user: dict = Depends(get_current_user_dep),
|
||||
db=Depends(get_db)
|
||||
):
|
||||
"""Get a specific POS transaction"""
|
||||
try:
|
||||
return {
|
||||
"id": str(transaction_id),
|
||||
"tenant_id": str(tenant_id),
|
||||
"status": "completed",
|
||||
"is_synced": True
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error("Failed to get POS transaction", error=str(e),
|
||||
tenant_id=tenant_id, transaction_id=transaction_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to get transaction: {str(e)}")
|
||||
Reference in New Issue
Block a user