11from fastapi import APIRouter , Header , Body , HTTPException
22from pydantic import BaseModel
33from typing import List , Dict , Any , Optional
4- from services .audit_service import process_audit_question
4+ from services .audit_service import process_audit_question , get_recent_activity
55from services .gemini_service import VisualizationConfig
6+ from services .user_queries_service import get_user_id_from_token
67
78router = APIRouter ()
89
@@ -18,16 +19,29 @@ class AuditQueryResponse(BaseModel):
1819 visualization : Optional [VisualizationConfig ] = None
1920
2021
22+ class RecentActivityItem (BaseModel ):
23+ database_name : str
24+ collection_name : str
25+ operation : str
26+ document_id : str
27+ user_email : str
28+ timestamp_utc : str
29+
30+
2131@router .post ("/query" , response_model = AuditQueryResponse )
2232def query_audit_log (
2333 body : AuditQueryRequest = Body (...), authorization : str = Header (...)
2434):
2535 if not authorization .startswith ("Bearer " ):
2636 raise HTTPException (status_code = 401 , detail = "Invalid token format" )
2737
28- # We might want to validate the token here even if we don't use it for the pg connection directly yet
29- # user_token = authorization.replace("Bearer ", "")
30- # access_token = exchange_token_obo(user_token)
31-
3238 response = process_audit_question (body .question )
3339 return AuditQueryResponse (** response )
40+
41+
42+ @router .get ("/recent" , response_model = List [RecentActivityItem ])
43+ def recent_activity (authorization : str = Header (...), limit : int = 10 ):
44+ if not authorization .startswith ("Bearer " ):
45+ raise HTTPException (status_code = 401 , detail = "Invalid token format" )
46+ user_email = get_user_id_from_token (authorization .replace ("Bearer " , "" ))
47+ return get_recent_activity (user_email = user_email , limit = min (limit , 50 ))
0 commit comments