1.9 KiB
1.9 KiB
Task: Create AlertService class
Goal
Create src/backend/services/alert_service.py with the AlertService class. This is Phase 1 of the alert refactor — only create the service, don't touch the router yet.
Requirements
Create src/backend/services/alert_service.py
Implement an AlertService class with these methods:
get_user_alerts(watchlist_id, status, page, page_size, user_id)— returns list of alert dicts + total countcreate_alert(watchlist_id, type, trigger_type, message, severity, ticker, metadata, user_id)— inserts alert, returns alert dictget_alert(alert_id, user_id)— returns alert dict or Noneupdate_alert(alert_id, updates_dict, user_id)— updates fields, returns alert dictresolve_alert(alert_id, user_id)— sets status='resolved', returns alert dictdismiss_alert(alert_id, user_id)— deletes alert, returns None_require_watchlist_owner(watchlist_id, user_id)— raises HTTPException if not owner
Implementation Details
- Import
execute_query,execute_command,execute_onefromdatabase - Import
HTTPExceptionfromfastapi - All methods should be
async - Use parameterized queries (no f-strings for SQL)
- Handle the
watchlist_id IN (...)pattern for listing alerts across multiple watchlists
Service Pattern
Follow the existing SentimentService or RotationService pattern for class structure.
Acceptance Criteria
- File
src/backend/services/alert_service.pyexists AlertServiceclass has all 7 methods listed above- File is under 200 lines (per RULES.md)
- Can be imported without errors:
from services.alert_service import AlertService
Files to Create
src/backend/services/alert_service.py
Files to Read First
src/backend/routers/alerts.py— extract logic from each endpointsrc/backend/services/sentiment_service.py— follow as pattern referencesrc/backend/services/rotation_service.py— follow as pattern reference