Backend: - Add game_metadata to create_game() and quick_create_game() endpoints - Fetch team display info (lname, sname, abbrev, color, thumbnail) from SBA API at game creation time and store in DB - Populate GameState with team display fields from game_metadata - Fix submit_team_lineup to cache lineup in state_manager after DB write so auto-start correctly detects both teams ready Frontend: - Read team colors/names/thumbnails from gameState instead of useState - Remove useState approach that failed across SSR navigation - Fix create.vue redirect from legacy /games/lineup/[id] to /games/[id] - Update game.vue header to show team names from gameState Docs: - Update CLAUDE.md to note dev mode has broken auth, always use prod Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
90 lines
2.5 KiB
Python
90 lines
2.5 KiB
Python
import logging
|
|
|
|
from fastapi import APIRouter, HTTPException, Query
|
|
from pydantic import BaseModel
|
|
|
|
from app.services.sba_api_client import sba_api_client
|
|
|
|
logger = logging.getLogger(f"{__name__}.teams")
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class TeamResponse(BaseModel):
|
|
"""Team information response"""
|
|
|
|
id: int
|
|
abbrev: str
|
|
sname: str
|
|
lname: str
|
|
color: str | None = None
|
|
thumbnail: str | None = None
|
|
manager_legacy: str | None = None
|
|
gmid: str | None = None
|
|
gmid2: str | None = None
|
|
division: dict | None = None
|
|
|
|
|
|
@router.get("/", response_model=list[TeamResponse])
|
|
async def get_teams(season: int = Query(..., description="Season number (e.g., 3)")):
|
|
"""
|
|
Get all active teams for a season from SBA API.
|
|
|
|
Args:
|
|
season: Season number to fetch teams for
|
|
|
|
Returns:
|
|
List of active teams (excludes IL teams)
|
|
"""
|
|
try:
|
|
logger.info(f"Fetching teams for season {season}")
|
|
teams = await sba_api_client.get_teams(season=season, active_only=True)
|
|
|
|
return [
|
|
TeamResponse(
|
|
id=team["id"],
|
|
abbrev=team["abbrev"],
|
|
sname=team["sname"],
|
|
lname=team["lname"],
|
|
color=team.get("color"),
|
|
thumbnail=team.get("thumbnail"),
|
|
manager_legacy=team.get("manager_legacy"),
|
|
gmid=team.get("gmid"),
|
|
gmid2=team.get("gmid2"),
|
|
division=team.get("division"),
|
|
)
|
|
for team in teams
|
|
]
|
|
|
|
except Exception as e:
|
|
logger.error(f"Failed to fetch teams: {e}", exc_info=True)
|
|
raise HTTPException(status_code=500, detail="Failed to fetch teams")
|
|
|
|
|
|
@router.get("/{team_id}/roster")
|
|
async def get_team_roster(
|
|
team_id: int,
|
|
season: int = Query(..., description="Season number (e.g., 3)"),
|
|
):
|
|
"""
|
|
Get roster for a specific team from SBA API.
|
|
|
|
Args:
|
|
team_id: Team ID
|
|
season: Season number to fetch roster for
|
|
|
|
Returns:
|
|
List of players on the team's roster
|
|
"""
|
|
try:
|
|
logger.info(f"Fetching roster for team {team_id}, season {season}")
|
|
roster = await sba_api_client.get_roster(team_id=team_id, season=season)
|
|
|
|
return {"count": len(roster), "players": roster}
|
|
|
|
except Exception as e:
|
|
logger.error(f"Failed to fetch roster for team {team_id}: {e}", exc_info=True)
|
|
raise HTTPException(
|
|
status_code=500, detail=f"Failed to fetch roster for team {team_id}"
|
|
)
|