1.8 KiB
1.8 KiB
Task: Migrate POST/PUT/DELETE endpoints to AlertService
Goal
Replace routers/alerts.py write endpoints (create_alert, update_alert, resolve_alert, dismiss_alert) to use AlertService.
Requirements
Changes to src/backend/routers/alerts.py
-
Replace
create_alert()body:- Call
service.create_alert(watchlist_id, type, trigger_type, message, severity, ticker, metadata, user_id) - Return
AlertResponsewrapping the result - Keep the watchlist owner check
- Call
-
Replace
update_alert()body:- Use
service.get_alert()to verify existence and ownership - Build updates dict from
bodyfields - Call
service.update_alert(alert_id, updates_dict, user_id) - Return
AlertResponsewrapping the result
- Use
-
Replace
resolve_alert()body:- Use
service.get_alert()to verify existence and ownership - Call
service.resolve_alert(alert_id, user_id) - Return
AlertResponsewrapping the result
- Use
-
Replace
dismiss_alert()body:- Use
service.get_alert()to verify existence and ownership - Call
service.dismiss_alert(alert_id, user_id) - Return
None(204 response)
- Use
Constraints
- Keep all route signatures, decorators, and response models unchanged
- Keep
check_all_alertsendpoint unchanged (it callscheck_sentiment_alertsdirectly) - File must stay under 200 lines total
Acceptance Criteria
- All write endpoints use
AlertServicemethods - All alert CRUD tests pass:
pytest tests/test_alerts.py -k "test_create or test_update or test_delete or test_resolve or test_dismiss" --tb=short - No import errors
Files to Modify
src/backend/routers/alerts.py
Files to Read First
src/backend/services/alert_service.pysrc/backend/routers/alerts.py— current write endpoint implementations