Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ai_services/api/endpoints/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

router = APIRouter()


@router.post("/incidents", response_model=IncidentOut)
def report_incident(payload: IncidentCreate, user=Depends(get_current_user)):
try:
payload.reported_by = user.get("email") # or user["id"]
return create_incident(payload.dict())
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

4 changes: 3 additions & 1 deletion ai_services/models/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 6 additions & 5 deletions ai_services/services/incident_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
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"],
"description": data["description"],
"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

Expand All @@ -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)
print(result)