bim-twin-viewer/backend/app/api/upload.py
warnason 520d55259f
Some checks are pending
CI / backend-lint-and-test (push) Waiting to run
Initial project scaffold: FastAPI backend + Vue.js frontend
- FastAPI with async SQLAlchemy models for IFC elements
- IFC file upload and parsing via IfcOpenShell
- REST API for projects, elements, and properties
- Vue.js 3 frontend shell with Three.js dependency
- Docker Compose for full-stack local development
- PostgreSQL 16 as database
- CI pipeline for Forgejo Actions
- Project documentation and API overview
2026-04-20 11:21:30 +02:00

31 lines
988 B
Python

"""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