Add REST API endpoints for team player statistics
Implemented complete REST API to retrieve NHL player statistics for entire teams:
Application Layer:
- Created DTOs for Player, SkaterStats, GoalieStats, and PlayerWithStatsDTO
- Implemented GetTeamPlayerStatsUseCase that orchestrates data retrieval
- Transforms domain entities to API-friendly DTOs
Presentation Layer:
- Created /api/v1/teams/{team_id}/players endpoint (all players)
- Created /api/v1/teams/{team_id}/players/skaters endpoint (skaters only)
- Created /api/v1/teams/{team_id}/players/goalies endpoint (goalies only)
- Integrated routes into main FastAPI application
Features:
- Retrieves complete roster for any NHL team by abbreviation
- Aggregates current season statistics for each player
- Differentiates between skater and goalie statistics
- Proper error handling with 404 for invalid teams
- Follows CLEAN architecture with dependency injection
Documentation:
- Created comprehensive API_GUIDE.md with usage examples
- Includes setup instructions, endpoint documentation
- Python, JavaScript, and cURL examples
- Complete list of NHL team abbreviations
Testing:
- Added test scripts for both direct adapter testing and REST API testing
- Verified functionality with Toronto Maple Leafs data
The REST API is now ready for integration with fantasy hockey analysis tools.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
53
debug_api.py
Normal file
53
debug_api.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Debug script to examine raw NHL API responses."""
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, "/Users/michaelsimard/dev/services/project-kempe-backend")
|
||||
|
||||
from nhlpy import NHLClient
|
||||
|
||||
client = NHLClient()
|
||||
|
||||
print("=" * 60)
|
||||
print("RAW API RESPONSE DEBUGGING")
|
||||
print("=" * 60)
|
||||
|
||||
# Test teams endpoint
|
||||
print("\n1. Testing teams endpoint...")
|
||||
try:
|
||||
teams_data = client.teams.teams()
|
||||
print(f" Response type: {type(teams_data)}")
|
||||
if isinstance(teams_data, dict):
|
||||
print(f" Keys: {list(teams_data.keys())}")
|
||||
if "data" in teams_data:
|
||||
print(f" Number of teams in 'data': {len(teams_data['data'])}")
|
||||
if teams_data["data"]:
|
||||
print(f" First team keys: {list(teams_data['data'][0].keys())}")
|
||||
print(f" First team sample: {teams_data['data'][0]}")
|
||||
else:
|
||||
print(f" Response: {teams_data}")
|
||||
except Exception as e:
|
||||
print(f" ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
# Test player game log
|
||||
print("\n2. Testing player game log (Sammy Blais ID: 8478104)...")
|
||||
try:
|
||||
game_log = client.stats.player_game_log(
|
||||
player_id="8478104", season_id="20242025", game_type=2
|
||||
)
|
||||
print(f" Response type: {type(game_log)}")
|
||||
if isinstance(game_log, dict):
|
||||
print(f" Keys: {list(game_log.keys())}")
|
||||
if "gameLog" in game_log:
|
||||
print(f" Number of games: {len(game_log['gameLog'])}")
|
||||
if game_log["gameLog"]:
|
||||
print(f" First game keys: {list(game_log['gameLog'][0].keys())}")
|
||||
else:
|
||||
print(f" Response: {game_log}")
|
||||
except Exception as e:
|
||||
print(f" ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
Reference in New Issue
Block a user