All Stories
5-1-sports-filtering-bettable-games-queryDoneEpic 5.1
Story 5.1: Sports Filtering & Bettable Games Query
Status: done
Tasks
- **Task 1: Create Sports API Endpoint** (AC: 1, 2, 3, 4, 5)
- 1.1 Create `/server/app/api/v1/endpoints/shared/sports.py`
- 1.2 Define `SportResponse` Pydantic schema with required fields
- 1.3 Implement `GET /sports` query using `sidebar_data` materialized view
- 1.4 Add `HAVING SUM(game_count) > 0` filter to exclude inactive sports
- 1.5 Apply American sports priority ordering (NFL=1, NBA=2, MLB=3, NHL=4, NCAAF=5, NCAAB=6, others=99)
- 1.6 Register router in `/server/app/api/v1/api.py`
- **Task 2: Implement Redis Caching** (AC: 6)
- 2.1 Define cache key `sports:bettable:v1` with 300s TTL
- 2.2 Implement cache-first pattern: check Redis → query DB → cache result
- 2.3 Add `force_refresh` query parameter to bypass cache
- 2.4 Include `cache_info` in response (hit/miss, source, ttl)
- **Task 3: Create Client Hook** (AC: 7)
- 3.1 Create `/client/src/hooks/useSports.ts` using TanStack Query
- 3.2 Configure `staleTime: 5 * 60 * 1000` (5 minutes)
- 3.3 Implement retry logic with exponential backoff
- 3.4 Export typed response interface for component consumption
- **Task 4: Testing** (AC: 1-7)
- 4.1 Write pytest tests for sports endpoint (happy path, empty result, cache behavior)
- 4.2 Write pytest test verifying game_count > 0 filter
- 4.3 Write pytest test verifying American sports priority ordering
- 4.4 Add integration test for Redis cache hit/miss scenarios (deferred)
Progress
Tasks3/4
Acceptance Criteria0
Total Tasks4