REFACTOR ALL APIs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# services/inventory/app/api/transformations.py
|
||||
"""
|
||||
API endpoints for product transformations
|
||||
Following standardized URL structure with role-based access control
|
||||
"""
|
||||
|
||||
from typing import List, Optional
|
||||
@@ -17,8 +18,14 @@ from app.schemas.inventory import (
|
||||
)
|
||||
from app.models.inventory import ProductionStage
|
||||
from shared.auth.decorators import get_current_user_dep
|
||||
from shared.auth.access_control import require_user_role, admin_role_required
|
||||
from shared.routing import RouteBuilder
|
||||
|
||||
logger = structlog.get_logger()
|
||||
|
||||
# Create route builder for consistent URL structure
|
||||
route_builder = RouteBuilder('inventory')
|
||||
|
||||
router = APIRouter(tags=["transformations"])
|
||||
|
||||
|
||||
@@ -40,7 +47,12 @@ def get_current_user_id(current_user: dict = Depends(get_current_user_dep)) -> U
|
||||
return None
|
||||
|
||||
|
||||
@router.post("/tenants/{tenant_id}/transformations", response_model=ProductTransformationResponse)
|
||||
@router.post(
|
||||
route_builder.build_base_route("transformations"),
|
||||
response_model=ProductTransformationResponse,
|
||||
status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
@require_user_role(['admin', 'owner', 'member'])
|
||||
async def create_transformation(
|
||||
transformation_data: ProductTransformationCreate,
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
@@ -68,7 +80,10 @@ async def create_transformation(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/transformations", response_model=List[ProductTransformationResponse])
|
||||
@router.get(
|
||||
route_builder.build_base_route("transformations"),
|
||||
response_model=List[ProductTransformationResponse]
|
||||
)
|
||||
async def get_transformations(
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
@@ -94,7 +109,10 @@ async def get_transformations(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/transformations/{transformation_id}", response_model=ProductTransformationResponse)
|
||||
@router.get(
|
||||
route_builder.build_resource_detail_route("transformations", "transformation_id"),
|
||||
response_model=ProductTransformationResponse
|
||||
)
|
||||
async def get_transformation(
|
||||
transformation_id: UUID = Path(..., description="Transformation ID"),
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
@@ -122,7 +140,10 @@ async def get_transformation(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/transformations/summary", response_model=dict)
|
||||
@router.get(
|
||||
route_builder.build_base_route("transformations/summary"),
|
||||
response_model=dict
|
||||
)
|
||||
async def get_transformation_summary(
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
days_back: int = Query(30, ge=1, le=365, description="Days back for summary"),
|
||||
@@ -141,7 +162,11 @@ async def get_transformation_summary(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/tenants/{tenant_id}/transformations/par-bake-to-fresh")
|
||||
@router.post(
|
||||
route_builder.build_operations_route("transformations/par-bake-to-fresh"),
|
||||
response_model=dict
|
||||
)
|
||||
@require_user_role(['admin', 'owner', 'member'])
|
||||
async def create_par_bake_transformation(
|
||||
source_ingredient_id: UUID = Query(..., description="Par-baked ingredient ID"),
|
||||
target_ingredient_id: UUID = Query(..., description="Fresh baked ingredient ID"),
|
||||
|
||||
Reference in New Issue
Block a user