Add CP→CA→PI platform foundation on MapMil monorepo.
Unify parsing workers, analytics API with PostgreSQL, map UI, and PI distribution into centers/ with Docker Compose. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..database import get_db
|
||||
from ..schemas import EventRead
|
||||
from ..services.filtering import apply_consumer_filter, find_consumer_by_api_key
|
||||
|
||||
router = APIRouter(prefix="/api/v1", tags=["distribution"])
|
||||
|
||||
|
||||
def get_consumer_from_api_key(
|
||||
authorization: str | None = Header(default=None),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
if not authorization or not authorization.startswith("Bearer "):
|
||||
raise HTTPException(status_code=401, detail="Missing or invalid Authorization header")
|
||||
|
||||
api_key = authorization.removeprefix("Bearer ").strip()
|
||||
consumer = find_consumer_by_api_key(db, api_key)
|
||||
if not consumer:
|
||||
raise HTTPException(status_code=401, detail="Invalid API key")
|
||||
return consumer
|
||||
|
||||
|
||||
@router.get("/events", response_model=list[EventRead])
|
||||
def list_filtered_events(
|
||||
limit: int = Query(default=100, ge=1, le=1000),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
consumer=Depends(get_consumer_from_api_key),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
events = apply_consumer_filter(db, consumer)
|
||||
return events[offset : offset + limit]
|
||||
Reference in New Issue
Block a user