strat-gameplay-webapp/backend/app/api/routes/schedule.py
Cal Corum fbbb1cc5da CLAUDE: Add SBA schedule integration with weekly matchup display
Implements schedule viewing from SBA production API with week navigation
and game creation from scheduled matchups. Groups games by team matchup
horizontally with games stacked vertically for space efficiency.

Backend:
- Add schedule routes (/api/schedule/current, /api/schedule/games)
- Add SBA API client methods for schedule data
- Fix multi-worker state isolation (single worker for in-memory state)
- Add Redis migration TODO for future scalability
- Support custom team IDs in quick-create endpoint

Frontend:
- Add Schedule tab as default on home page
- Week navigation with prev/next and "Current Week" jump
- Horizontal group layout (2-6 columns responsive)
- Completed games show score + "Final" badge (no Play button)
- Incomplete games show "Play" button to create webapp game

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 23:39:31 -06:00

80 lines
1.9 KiB
Python

"""
SBA Schedule API routes.
Provides endpoints to fetch current season/week and scheduled games
from the SBA production API.
"""
import logging
from typing import Any
from fastapi import APIRouter, HTTPException
from app.services.sba_api_client import sba_api_client
logger = logging.getLogger(f"{__name__}.schedule")
router = APIRouter()
@router.get("/current")
async def get_current() -> dict[str, Any]:
"""
Get current season and week from SBA API.
Returns:
Dictionary with season and week numbers
Example response:
{"season": 13, "week": 12}
"""
try:
return await sba_api_client.get_current()
except Exception as e:
logger.error(f"Failed to get current season/week: {e}")
raise HTTPException(
status_code=502, detail="Failed to fetch current season/week from SBA API"
)
@router.get("/games")
async def get_schedule_games(
season: int,
week: int,
) -> list[dict[str, Any]]:
"""
Get scheduled games for a specific week from SBA API.
Args:
season: Season number (e.g., 13)
week: Week number within the season
Returns:
List of game dictionaries with team matchup info
Example response:
[
{
"id": 12345,
"season": 13,
"week": 12,
"home_team_id": 35,
"away_team_id": 42,
"home_abbrev": "STL",
"away_abbrev": "CHC",
...
}
]
"""
try:
games = await sba_api_client.get_schedule_games(
season=season, week_start=week, week_end=week
)
return games
except Exception as e:
logger.error(f"Failed to get schedule games for S{season} W{week}: {e}")
raise HTTPException(
status_code=502,
detail=f"Failed to fetch schedule games from SBA API for season {season}, week {week}",
)