1.6 KiB
1.6 KiB
Task: Migrate GET endpoints to AlertService
Goal
Replace routers/alerts.py GET endpoints (get_user_alerts, get_alert) to use AlertService instead of direct DB calls.
Requirements
Changes to src/backend/routers/alerts.py
- Import
AlertServicefromservices.alert_service - Create a service instance:
service = AlertService() - Replace
get_user_alerts()body:- Remove all DB query logic (the ~40 lines of query building)
- Call
service.get_user_alerts(watchlist_id, status, page, page_size, user_id) - Return the result wrapped in
AlertListResponse
- Replace
get_alert()body:- Use
service.get_alert(alert_id, user_id) - Keep the watchlist owner check using
service._require_watchlist_owner() - Return result wrapped in
AlertResponse
- Use
Constraints
- Keep the existing route signatures, decorators, and response models unchanged
- Keep the
resolve_alert,dismiss_alert,update_alert, andcreate_alertmethods calling DB directly (they will be migrated in the next task) - File must stay under 200 lines total
Acceptance Criteria
get_user_alertsusesAlertService.get_user_alerts()internallyget_alertusesAlertService.get_alert()internally- All existing GET tests still pass:
pytest tests/test_alerts.py -k "get" --tb=short - No import errors
Files to Modify
src/backend/routers/alerts.py
Files to Read First
src/backend/services/alert_service.py— the service created in the previous tasksrc/backend/routers/alerts.py— current GET endpoint implementations