WAGERBABE DOCS
All Stories
9-10-cash-out-activity-feedReadyEpic 9.10

Story 9.10: Cash Out Activity Feed

Status: ready-for-dev

Tasks

  • Task 1: Create Pydantic schemas for cash out activity (AC: #3, #4, #6)
    • 1.1: Create `server/app/schemas/agent/cash_out.py` with `CashOutActivity` model
    • 1.2: Create `CashOutTotals` model (total_count, total_cash_out_amount, total_profit_loss)
    • 1.3: Create `CashOutActivityResponse` model with pagination metadata
    • 1.4: Create `CashOutSummaryResponse` model for dashboard widget
    • 1.5: Add unit tests for schema validation
  • Task 2: Implement cash out activity endpoint (AC: #1, #2, #3, #4, #6)
    • 2.1: Create `server/app/api/v1/endpoints/agents/cash_out.py` router
    • 2.2: Implement `GET /api/v1/agent/cash-out/activity` endpoint with pagination
    • 2.3: Add customer_id, date_from, date_to query parameters
    • 2.4: Query bets table with `status = 'cashed_out'` filtered by agent's customers
    • 2.5: Calculate profit_loss as (cash_out_amount - stake) per bet
    • 2.6: Return totals aggregation for filtered results
    • 2.7: Add agent ownership verification (users.agent_id = current_agent.id)
    • 2.8: Add integration tests for endpoint behavior
  • Task 3: Implement cash out summary endpoint (AC: #6, #7)
    • 3.1: Implement `GET /api/v1/agent/cash-out/summary` endpoint
    • 3.2: Add period query parameter (24h, 7d, 30d)
    • 3.3: Calculate summary metrics (total_cash_outs, unique_customers, net_profit_loss)
    • 3.4: Calculate auto_cash_out_percentage
    • 3.5: Calculate avg_return_ratio (cash_out_amount / stake)
    • 3.6: Return top 5 customers by cash out activity
    • 3.7: Add integration tests for summary endpoint
  • Task 4: Implement real-time SSE stream (AC: #5)
    • 4.1: Create `server/app/api/v1/endpoints/agents/cash_out_stream.py` router
    • 4.2: Implement `GET /api/v1/agent/cash-out/stream` SSE endpoint
    • 4.3: Subscribe to Redis pubsub channel `agent:cash_out:{agent_id}`
    • 4.4: Stream cash out events as SSE (Server-Sent Events)
    • 4.5: Add proper connection handling and cleanup
    • 4.6: Add integration tests for SSE stream
  • Task 5: Add cash out event publishing (AC: #5)
    • 5.1: Update bet settlement service to publish cash out events
    • 5.2: Publish to Redis pubsub on `status = 'cashed_out'` transition
    • 5.3: Include bet details (user_id, bet_id, cash_out_amount, profit_loss)
    • 5.4: Add unit tests for event publishing
  • Task 6: Create frontend CashOutActivityFeed component (AC: #7)
    • 6.1: Create `client/src/components/composite/agent/cash-out-activity-feed.tsx`
    • 6.2: Implement useQuery hook for `/agent/cash-out/activity`
    • 6.3: Add EventSource listener for real-time SSE updates
    • 6.4: Display cash out list with profit/loss color coding
    • 6.5: Show auto cash out badges and trigger reasons
    • 6.6: Display summary totals in footer
    • 6.7: Add toast notifications for new cash outs
    • 6.8: Add mobile-responsive styling
  • Task 7: Database schema validation (AC: #3, #4)
    • 7.1: Verify bets table has `cash_out_amount` column
    • 7.2: Verify bets table has `is_auto_cash_out` column
    • 7.3: Verify bets table has `cash_out_trigger_reason` column
    • 7.4: Verify bets table has `settled_at` timestamp column
    • 7.5: Add database index on `status, settled_at` for performance
    • 7.6: Add database index on `user_id, status` for agent queries
  • Task 8: Register router and test integration (AC: all)
    • 8.1: Register cash_out router in `server/app/api/v1/__init__.py`
    • 8.2: Register cash_out_stream router in `server/app/api/v1/__init__.py`
    • 8.3: Add end-to-end integration tests
    • 8.4: Test pagination behavior (limit, offset)
    • 8.5: Test filtering by customer and date range
    • 8.6: Test SSE connection and event delivery
    • 8.7: Verify agent authorization prevents cross-agent data access

Progress

Tasks0/8
Acceptance Criteria0
Total Tasks8