major-domo-v2/models/draft_list.py
Cal Corum 5f69d495ab CLAUDE: Fix draft list operations and improve add success display
Multiple fixes for draft list functionality:

1. **Model Fix (draft_list.py):**
   - API returns nested Team and Player objects, not just IDs
   - Changed team_id/player_id from fields to @property methods
   - Extract IDs from nested objects via properties
   - Fixes Pydantic validation errors on GET operations

2. **Service Fix (draft_list_service.py):**
   - Override _extract_items_and_count_from_response() for API quirk
   - GET returns items under 'picks' key (not 'draftlist')
   - Changed add_to_list() return type from single entry to full list
   - Return verification list instead of trying to create new DraftList
   - Fixes "Failed to add" error from validation issues

3. **Command Enhancement (list.py):**
   - Display full draft list on successful add (not just confirmation)
   - Show position where player was added
   - Reuse existing create_draft_list_embed() for consistency
   - Better UX - user sees complete context after adding player

API Response Format:
GET: {"count": N, "picks": [{team: {...}, player: {...}}]}
POST: {"count": N, "draft_list": [{team_id: X, player_id: Y}]}

This resolves:
- Empty list after adding player (Pydantic validation)
- "Add Failed" error despite successful operation
- Poor UX with minimal success feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 19:35:50 -05:00

40 lines
1.1 KiB
Python

"""
Draft preference list model
Represents team draft board rankings and preferences.
"""
from typing import Optional
from pydantic import Field
from models.base import SBABaseModel
from models.team import Team
from models.player import Player
class DraftList(SBABaseModel):
"""Draft preference list entry for a team."""
season: int = Field(..., description="Draft season")
rank: int = Field(..., description="Ranking of player on team's draft board")
# API returns nested objects (not just IDs)
team: Team = Field(..., description="Team object")
player: Player = Field(..., description="Player object")
@property
def team_id(self) -> int:
"""Extract team ID from nested team object."""
return self.team.id
@property
def player_id(self) -> int:
"""Extract player ID from nested player object."""
return self.player.id
@property
def is_top_ranked(self) -> bool:
"""Check if this is the team's top-ranked available player."""
return self.rank == 1
def __str__(self):
return f"{self.team.abbrev} Draft Board #{self.rank}: {self.player.name}"