Skip to content

Conversation

@aLEGEND21
Copy link
Collaborator

The current system tracks complaints as their own table while warnings and citations are stored as integer counters on the Location entity. This creates inconsistency in how we track incidents and makes it difficult to view the history or details of individual warnings/citations. This PR consolidates all three incident types into a single Incidents table with a severity field.

Changes:

New Incident Module

  • Added incident_entity.py, incident_model.py, incident_service.py, and incident_router.py to replace the complaint module
  • Added IncidentSeverity enum with values: complaint, warning, citation
  • Added severity field to incident data model and entity

Location Entity Updates

  • Removed warning_count and citation_count columns since these are now derived from the incidents table
  • Renamed complaints relationship to incidents
  • Updated LocationDto to return incidents list instead of complaints
  • Removed MAX_COUNT constant and count validation logic

Removed Increment Routes

  • Deleted POST /api/police/locations/{id}/warnings and POST /api/police/locations/{id}/citations endpoints
  • Deleted the now-empty police_router.py since police credential routes live in account_router.py
  • Deleted increment_warnings() and increment_citations() methods from LocationService

Test Updates

  • Created new incident test files (incident_utils.py, incident_service_test.py, incident_router_test.py)
  • Updated location tests to use incidents instead of complaints and removed count-related tests
  • Deleted complaint test files and police router tests

Script Updates

  • Updated reset_dev.py to remove warning_count and citation_count from location seeding

Cursor was helpful with making these changes, but I reviewed all AI-made changes prior to committing the code.

Closes #127

@aLEGEND21 aLEGEND21 requested a review from naasanov January 27, 2026 19:34
@github-actions
Copy link

Test Results Summary

295 tests   - 7   295 ✅  - 7   12s ⏱️ -1s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit c4b061a. ± Comparison against base commit c972c7c.

This pull request removes 44 and adds 37 tests. Note that renamed tests count towards both.
test.modules.complaint.complaint_router_test ‑ test_complaint_authentication[allowed_roles0-GET-/api/locations/1/complaints-None]
test.modules.complaint.complaint_router_test ‑ test_complaint_authentication[allowed_roles1-POST-/api/locations/1/complaints-body1]
test.modules.complaint.complaint_router_test ‑ test_complaint_authentication[allowed_roles2-PUT-/api/locations/1/complaints/1-body2]
test.modules.complaint.complaint_router_test ‑ test_complaint_authentication[allowed_roles3-DELETE-/api/locations/1/complaints/1-None]
test.modules.complaint.complaint_router_test.TestComplaintRouter ‑ test_create_complaint_location_id_required
test.modules.complaint.complaint_router_test.TestComplaintRouter ‑ test_create_complaint_success
test.modules.complaint.complaint_router_test.TestComplaintRouter ‑ test_create_complaint_with_empty_description
test.modules.complaint.complaint_router_test.TestComplaintRouter ‑ test_delete_complaint_not_found
test.modules.complaint.complaint_router_test.TestComplaintRouter ‑ test_delete_complaint_success
test.modules.complaint.complaint_router_test.TestComplaintRouter ‑ test_get_complaints_by_location_empty
…
test.modules.incident.incident_router_test ‑ test_incident_authentication[allowed_roles0-GET-/api/locations/1/incidents-None]
test.modules.incident.incident_router_test ‑ test_incident_authentication[allowed_roles1-POST-/api/locations/1/incidents-body1]
test.modules.incident.incident_router_test ‑ test_incident_authentication[allowed_roles2-PUT-/api/locations/1/incidents/1-body2]
test.modules.incident.incident_router_test ‑ test_incident_authentication[allowed_roles3-DELETE-/api/locations/1/incidents/1-None]
test.modules.incident.incident_router_test.TestIncidentRouter ‑ test_create_incident_location_id_required
test.modules.incident.incident_router_test.TestIncidentRouter ‑ test_create_incident_severity_required
test.modules.incident.incident_router_test.TestIncidentRouter ‑ test_create_incident_success
test.modules.incident.incident_router_test.TestIncidentRouter ‑ test_create_incident_with_empty_description
test.modules.incident.incident_router_test.TestIncidentRouter ‑ test_create_incident_with_severity
test.modules.incident.incident_router_test.TestIncidentRouter ‑ test_delete_incident_not_found
…

@aLEGEND21 aLEGEND21 changed the title refactor: Store warnings/complaints as a separate Incident table Incidents Backend Refactor Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incidents Backend Refactor

2 participants