Initial Aurora Core 0.1 implementation
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
Production-grade media metadata backend per docs/aurora-core-spec.md: Aurora-owned UUIDv7 identity system, normalized movie/TV/people/credits schema, provider abstraction with a TMDb adapter, an idempotent async ingestion pipeline (normalize -> match -> upsert -> provenance), a Postgres FTS/trigram search layer, a stateless FastAPI v1 API with Redis caching/rate-limiting, arq workers, dev/prod Docker Compose topologies, unit + integration + load tests, CI, and architecture/ database/API/ERD documentation. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Shared FastAPI dependencies and helpers for the v1 API."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
from redis.asyncio import Redis
|
||||
|
||||
from app.services.cache import cache_get_json, cache_set_json
|
||||
|
||||
|
||||
def not_found(entity_type: str, aurora_id_str: str) -> HTTPException:
|
||||
return HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail={"code": f"{entity_type}_not_found", "message": f"No such {entity_type}: {aurora_id_str}"},
|
||||
)
|
||||
|
||||
|
||||
async def cached_response[T: BaseModel](
|
||||
redis: Redis,
|
||||
key: str,
|
||||
model: type[T],
|
||||
loader: Callable[[], Awaitable[T]],
|
||||
ttl: int | None = None,
|
||||
) -> T:
|
||||
"""Serve `model` from Redis if present, otherwise call `loader`, cache
|
||||
the result, and return it. Fails open to `loader` on any cache error."""
|
||||
|
||||
cached = await cache_get_json(redis, key)
|
||||
if cached is not None:
|
||||
return model.model_validate(cached)
|
||||
|
||||
result = await loader()
|
||||
await cache_set_json(redis, key, result.model_dump(mode="json"), ttl=ttl)
|
||||
return result
|
||||
Reference in New Issue
Block a user