Peter Mutwiri commited on
Commit
4d17e4d
Β·
1 Parent(s): 12e51aa

refacroed compute endpoint

Browse files
Files changed (1) hide show
  1. app/main.py +7 -4
app/main.py CHANGED
@@ -232,11 +232,16 @@ async def add_request_tracking(request: Request, call_next):
232
 
233
  # ─── KPI Computation Endpoint ──────────────────────────────────────────────────
234
  # ─── KPI Computation Endpoint ──────────────────────────────────────────────────
 
 
 
 
235
  @app.post("/api/v1/kpi/compute")
236
  async def compute_kpis(
237
- background_tasks: BackgroundTasks, # βœ… First parameter, no default needed
 
238
  source_id: str = Query(..., description="Data source ID"),
239
- current_user: dict = Depends(get_current_user),
240
  limited_org: str = Depends(rate_limit_org(max_requests=50))
241
  ):
242
  """
@@ -244,8 +249,6 @@ async def compute_kpis(
244
  Returns immediately; results published to Redis stream.
245
  """
246
  try:
247
- org_id = current_user["org_id"]
248
-
249
  # Check cache first
250
  cached = event_hub.get_key(f"kpi_cache:{org_id}:{source_id}")
251
  if cached:
 
232
 
233
  # ─── KPI Computation Endpoint ──────────────────────────────────────────────────
234
  # ─── KPI Computation Endpoint ──────────────────────────────────────────────────
235
+ # At top of app/main.py - add import
236
+ from app.deps import verify_api_key, rate_limit_org
237
+
238
+ # Replace the compute_kpis function
239
  @app.post("/api/v1/kpi/compute")
240
  async def compute_kpis(
241
+ background_tasks: BackgroundTasks,
242
+ org_id: str = Query(..., description="Organization ID"),
243
  source_id: str = Query(..., description="Data source ID"),
244
+ api_key: str = Depends(verify_api_key), # βœ… Returns string, not HTTPAuthorizationCredentials
245
  limited_org: str = Depends(rate_limit_org(max_requests=50))
246
  ):
247
  """
 
249
  Returns immediately; results published to Redis stream.
250
  """
251
  try:
 
 
252
  # Check cache first
253
  cached = event_hub.get_key(f"kpi_cache:{org_id}:{source_id}")
254
  if cached: