commit df921f13cd8c236e9898c980ba1f3bee6e49f25d Author: rockdrigo Date: Tue Nov 24 11:18:08 2026 -0600 Rebuild: FastAPI skeleton with health, domains, run status and the auth seam Co-Authored-By: Claude Opus 5.5 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c56ff1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +.pytest_cache/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f840617 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "webapi" +version = "0.0.0" +description = "FastAPI: FHIR routes, control routes, the auth dependency." +requires-python = ">=3.12" +dependencies = ["core", "persistance", "fastapi[standard]", "dagster-graphql"] + +[build-system] +requires = ["uv_build>=0.12,<0.13"] +build-backend = "uv_build" + +[tool.uv.build-backend] +module-name = "webapi" +module-root = "" +[tool.uv.sources] +core = { workspace = true } +persistance = { workspace = true } diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..7da15ef --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,26 @@ +from dagster import DagsterRunStatus +from fastapi.testclient import TestClient + +from webapi.main import app, dagster + + +class FakeDagster: + def get_run_status(self, run_id): + return DagsterRunStatus.SUCCESS + + +def test_health(): + assert TestClient(app).get("/health").json() == {"status": "ok"} + + +def test_run_status_reads_dagster(): + app.dependency_overrides[dagster] = FakeDagster + try: + r = TestClient(app).get("/runs/abc") + finally: + app.dependency_overrides.clear() + assert r.json() == {"id": "abc", "status": "SUCCESS"} + + +def test_domains(): + assert TestClient(app).get("/domains").json() == ["cacu", "cama", "tea"] diff --git a/webapi/__init__.py b/webapi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/webapi/auth.py b/webapi/auth.py new file mode 100644 index 0000000..59e7ecf --- /dev/null +++ b/webapi/auth.py @@ -0,0 +1,12 @@ +"""The one dependency every route goes through. Open for now; this is where auth will go.""" + +from dataclasses import dataclass + + +@dataclass(frozen=True) +class Caller: + id: str = "anonymous" + + +def caller() -> Caller: + return Caller() diff --git a/webapi/main.py b/webapi/main.py new file mode 100644 index 0000000..9e47ac9 --- /dev/null +++ b/webapi/main.py @@ -0,0 +1,41 @@ +import os + +from dagster_graphql import DagsterGraphQLClient, DagsterGraphQLClientError +from fastapi import Depends, FastAPI, HTTPException + +from core.domains import Domain +from webapi.auth import caller + +app = FastAPI( + title="ISSSTELEON", + version="0.0.0", + dependencies=[Depends(caller)], + generate_unique_id_function=lambda route: route.name, # clean names in the generated client +) + + +def dagster() -> DagsterGraphQLClient: + return DagsterGraphQLClient( + os.environ.get("DAGSTER_HOST", "localhost"), + port_number=int(os.environ.get("DAGSTER_PORT", "3000")), + ) + + +@app.get("/health") +def health() -> dict[str, str]: + return {"status": "ok"} + + +@app.get("/domains") +def domains() -> list[Domain]: + return list(Domain) + + +@app.get("/runs/{run_id}") +def run_status(run_id: str, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: + try: + return {"id": run_id, "status": client.get_run_status(run_id).value} + except DagsterGraphQLClientError as e: + raise HTTPException( + status_code=404 if "RunNotFound" in str(e) else 502, detail=str(e) + ) from e diff --git a/webapi/openapi.py b/webapi/openapi.py new file mode 100644 index 0000000..e0c42f8 --- /dev/null +++ b/webapi/openapi.py @@ -0,0 +1,8 @@ +"""Print the OpenAPI document; the WebApp generates its client from it.""" + +import json + +from webapi.main import app + +if __name__ == "__main__": + print(json.dumps(app.openapi(), indent=1, sort_keys=True))