Files

38 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

# 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`
1. Import `AlertService` from `services.alert_service`
2. Create a service instance: `service = AlertService()`
3. 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`
4. 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`
### Constraints
- Keep the existing route signatures, decorators, and response models unchanged
- Keep the `resolve_alert`, `dismiss_alert`, `update_alert`, and `create_alert` methods calling DB directly (they will be migrated in the next task)
- File must stay under 200 lines total
## Acceptance Criteria
1. `get_user_alerts` uses `AlertService.get_user_alerts()` internally
2. `get_alert` uses `AlertService.get_alert()` internally
3. All existing GET tests still pass: `pytest tests/test_alerts.py -k "get" --tb=short`
4. 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 task
- `src/backend/routers/alerts.py` — current GET endpoint implementations