577dd1ca7e
- Rewrite CLAUDE.md to match current 8-service architecture (was 11, 5 deleted) - Remove all as-any casts in OrderDetail.tsx (9 casts → 0) - Add cad_parsed_objects/cad_part_materials to OrderItem interface - Rename require_admin → require_global_admin across 6 router files (22 calls) - Remove EXPORT_GLB_PRODUCTION enum + generate_gltf_production_task (dead code) - Remove worker-thumbnail from ALLOWED_SERVICES, replace Flamenco link - Delete obsolete PLAN.md (1455 lines) and PLAN_REFACTOR.md (1174 lines) - Fix digit-only USD prim names with p_ prefix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
import uuid
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database import get_db
|
|
from app.models import GlobalRenderPosition
|
|
from app.domains.rendering.schemas import (
|
|
GlobalRenderPositionCreate,
|
|
GlobalRenderPositionPatch,
|
|
GlobalRenderPositionOut,
|
|
)
|
|
from app.utils.auth import require_global_admin, get_current_user
|
|
|
|
router = APIRouter(prefix="/render-positions/global", tags=["global-render-positions"])
|
|
|
|
|
|
@router.get("", response_model=list[GlobalRenderPositionOut])
|
|
async def list_global_render_positions(
|
|
db: AsyncSession = Depends(get_db),
|
|
_user=Depends(get_current_user),
|
|
):
|
|
"""List all global render positions (available to all authenticated users)."""
|
|
result = await db.execute(
|
|
select(GlobalRenderPosition).order_by(GlobalRenderPosition.sort_order, GlobalRenderPosition.name)
|
|
)
|
|
return result.scalars().all()
|
|
|
|
|
|
@router.post("", response_model=GlobalRenderPositionOut, status_code=status.HTTP_201_CREATED)
|
|
async def create_global_render_position(
|
|
body: GlobalRenderPositionCreate,
|
|
db: AsyncSession = Depends(get_db),
|
|
_user=Depends(require_global_admin),
|
|
):
|
|
"""Create a new global render position (admin only)."""
|
|
pos = GlobalRenderPosition(**body.model_dump())
|
|
db.add(pos)
|
|
await db.commit()
|
|
await db.refresh(pos)
|
|
return pos
|
|
|
|
|
|
@router.patch("/{pos_id}", response_model=GlobalRenderPositionOut)
|
|
async def update_global_render_position(
|
|
pos_id: uuid.UUID,
|
|
body: GlobalRenderPositionPatch,
|
|
db: AsyncSession = Depends(get_db),
|
|
_user=Depends(require_global_admin),
|
|
):
|
|
"""Update a global render position (admin only)."""
|
|
result = await db.execute(select(GlobalRenderPosition).where(GlobalRenderPosition.id == pos_id))
|
|
pos = result.scalar_one_or_none()
|
|
if not pos:
|
|
raise HTTPException(status_code=404, detail="Global render position not found")
|
|
for field, value in body.model_dump(exclude_unset=True).items():
|
|
setattr(pos, field, value)
|
|
await db.commit()
|
|
await db.refresh(pos)
|
|
return pos
|
|
|
|
|
|
@router.delete("/{pos_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_global_render_position(
|
|
pos_id: uuid.UUID,
|
|
db: AsyncSession = Depends(get_db),
|
|
_user=Depends(require_global_admin),
|
|
):
|
|
"""Delete a global render position (admin only)."""
|
|
result = await db.execute(select(GlobalRenderPosition).where(GlobalRenderPosition.id == pos_id))
|
|
pos = result.scalar_one_or_none()
|
|
if not pos:
|
|
raise HTTPException(status_code=404, detail="Global render position not found")
|
|
await db.delete(pos)
|
|
await db.commit()
|