diff --git a/ai_services/api/endpoints/incidents.py b/ai_services/api/endpoints/incidents.py index 1f46e5e..746cf2b 100644 --- a/ai_services/api/endpoints/incidents.py +++ b/ai_services/api/endpoints/incidents.py @@ -6,6 +6,7 @@ router = APIRouter() + @router.post("/incidents", response_model=IncidentOut) def report_incident(payload: IncidentCreate, user=Depends(get_current_user)): try: @@ -13,4 +14,3 @@ def report_incident(payload: IncidentCreate, user=Depends(get_current_user)): return create_incident(payload.dict()) except Exception as e: raise HTTPException(status_code=500, detail=str(e)) - \ No newline at end of file diff --git a/ai_services/models/incident.py b/ai_services/models/incident.py index b60ccc5..cb107bd 100644 --- a/ai_services/models/incident.py +++ b/ai_services/models/incident.py @@ -3,14 +3,16 @@ from typing import Optional from datetime import datetime + class IncidentCreate(BaseModel): title: str description: str location: Optional[str] = None # reported_by: Optional[str] = None # Could be user_id or email + class IncidentOut(BaseModel): - id: str + id: str title: str description: str location: Optional[str] diff --git a/ai_services/services/incident_service.py b/ai_services/services/incident_service.py index d286da1..9fc108d 100644 --- a/ai_services/services/incident_service.py +++ b/ai_services/services/incident_service.py @@ -4,10 +4,11 @@ from uuid import uuid4 from datetime import datetime + def create_incident(data: dict) -> dict: severity = triage_incident(data["description"]) incident_id = str(uuid4()) - + new_incident = { "id": incident_id, "title": data["title"], @@ -15,9 +16,9 @@ def create_incident(data: dict) -> dict: "location": data.get("location"), "reported_by": data.get("reported_by"), "severity": severity, - "created_at": datetime.utcnow().isoformat() + "created_at": datetime.utcnow().isoformat(), } - + response = supabase.table("incidents").insert(new_incident).execute() return response.data[0] if response.data else new_incident @@ -27,7 +28,7 @@ def create_incident(data: dict) -> dict: "title": "Unauthorized Access Detected", "description": "An unknown individual was seen entering the restricted server room.", "location": "Server Room 3", - "reported_by": "John Doe" + "reported_by": "John Doe", } result = create_incident(sample_data) - print(result) \ No newline at end of file + print(result)