All Stories
11-3-manage-preferencesReadyEpic 11.3
Story 11.3: Manage Preferences
Status: ready-for-dev
Tasks
- Task 1: Create Preferences Endpoint (AC: 2, 3)
- 1.1 Create `server/app/api/v1/endpoints/users/preferences.py` file
- 1.2 Create `UserPreferencesRequest` Pydantic model with optional fields
- 1.3 Add field validators for theme (system/light/dark), odds_format (american/decimal/fractional)
- 1.4 Implement `GET /api/v1/user/preferences` endpoint with get_current_user dependency
- 1.5 Query users table for theme, odds_format, timezone, currency, language, default_stake
- 1.6 Query JSONB columns: notifications_preferences, privacy_settings, security_settings
- 1.7 Return structured response with preferences, notifications, privacy, security objects
- 1.8 Implement `PUT /api/v1/user/preferences` endpoint for updating preferences
- 1.9 Build update_data dict with only provided fields (partial updates)
- 1.10 Add preferences_updated_at timestamp to all updates
- Task 2: Create JSONB Preference Endpoints (AC: 4, 5, 6)
- 2.1 Implement `PUT /api/v1/user/preferences/notifications` endpoint
- 2.2 Accept Dict[str, Any] for notifications payload (phone, sms, push settings)
- 2.3 Update notifications_preferences JSONB column in users table
- 2.4 Implement `PUT /api/v1/user/preferences/privacy` endpoint
- 2.5 Accept Dict[str, Any] for privacy payload (profileVisibility, showBettingStats, shareActivity)
- 2.6 Update privacy_settings JSONB column
- 2.7 Implement `PUT /api/v1/user/preferences/security` endpoint
- 2.8 Accept Dict[str, Any] for security payload (twoFactorEnabled, sessionTimeout, loginNotifications)
- 2.9 Update security_settings JSONB column
- Task 3: Register Preferences Router (AC: 2-6)
- 3.1 Add `from app.api.v1.endpoints.users import preferences` to `__init__.py`
- 3.2 Add `router.include_router(preferences.router, prefix="/preferences", tags=["preferences"])`
- 3.3 Verify router registration in FastAPI docs at /docs
- Task 4: Implement Password Change Endpoint (AC: 10, 11)
- 4.1 Create `ChangePasswordRequest` Pydantic model in profile.py
- 4.2 Add fields: current_password (str), new_password (str)
- 4.3 Add field validator for new_password with strength requirements
- 4.4 Validate min 8 characters, uppercase, lowercase, digit
- 4.5 Implement `POST /api/v1/user/change-password` endpoint
- 4.6 Query users table to get current password_hash
- 4.7 Verify current password using bcrypt.checkpw()
- 4.8 Return 401 if current password is incorrect
- 4.9 Hash new password using bcrypt with cost factor 12
- 4.10 Update password_hash and updated_at timestamp
- Task 5: Frontend Integration (AC: 1, 7, 8, 9)
- 5.1 Verify settings-interface.tsx is using correct API endpoints
- 5.2 Update API calls to use /api/v1/user/preferences endpoints
- 5.3 Implement odds format preference sync with odds display components
- 5.4 Apply theme preference to ThemeContext/ThemeProvider
- 5.5 Apply timezone preference to all timestamp formatting utilities
- 5.6 Add optimistic updates for immediate UI feedback
- 5.7 Handle loading states and error messages for preference updates
- Task 6: Database Schema Updates (AC: 2-6)
- 6.1 Verify users table has theme, odds_format, timezone, currency, language, default_stake columns
- 6.2 Verify users table has notifications_preferences JSONB column
- 6.3 Verify users table has privacy_settings JSONB column
- 6.4 Verify users table has security_settings JSONB column
- 6.5 Verify users table has preferences_updated_at timestamp column
- 6.6 Create migration if columns are missing
- Task 7: Testing (AC: 1-12)
- 7.1 Unit test: GET preferences returns correct structure with defaults
- 7.2 Unit test: PUT preferences updates only provided fields (partial updates)
- 7.3 Unit test: Theme validator rejects invalid values
- 7.4 Unit test: Odds format validator rejects invalid values
- 7.5 Unit test: PUT notifications updates JSONB column correctly
- 7.6 Unit test: PUT privacy updates JSONB column correctly
- 7.7 Unit test: PUT security updates JSONB column correctly
- 7.8 Unit test: Password change validates current password
- 7.9 Unit test: Password change rejects weak passwords
- 7.10 Unit test: Password change updates hash correctly
- 7.11 Integration test: Full preference update flow completes < 300ms
- 7.12 Integration test: Frontend preferences sync with backend state
- Task 8: Documentation (AC: 1-12)
- 8.1 Add OpenAPI schema documentation for all preference endpoints
- 8.2 Document JSONB structure for notifications, privacy, security
- 8.3 Document password change endpoint with security notes
- 8.4 Add inline code comments for field validators
Progress
Tasks0/8
Acceptance Criteria0
Total Tasks8