"""API route for IFC file upload and parsing.""" from fastapi import APIRouter, Depends, HTTPException, UploadFile from sqlalchemy.ext.asyncio import AsyncSession from app.models.database import get_db from app.schemas.element import ProjectOut from app.services.ifc_parser import parse_ifc_file router = APIRouter(tags=["upload"]) @router.post("/upload", response_model=ProjectOut) async def upload_ifc(file: UploadFile, db: AsyncSession = Depends(get_db)): """Upload an IFC file, parse it, and store elements in the database.""" if not file.filename.lower().endswith(".ifc"): raise HTTPException(status_code=400, detail="Only .ifc files are accepted") contents = await file.read() try: project = await parse_ifc_file( filename=file.filename, content=contents, db=db, ) except Exception as e: raise HTTPException(status_code=422, detail=f"Failed to parse IFC file: {e}") return project