Commit Graph

4 Commits

Author SHA1 Message Date
Michael Simard
c10fdd594d 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>
2025-11-23 22:44:39 -06:00
Michael Simard
28169863df Fix NHL API adapter to handle actual API response structures
Corrected data parsing issues discovered during testing:

Teams Endpoint:
- Fixed get_all_teams to handle list response (not dict with "data" key)
- Corrected team name parsing to avoid duplication
- Properly extract city from full team name using common_name
- Fixed division and conference extraction from nested dict structures

Stats Endpoints:
- Fixed game log parsing to handle list response (not dict with "gameLog" key)
- Applied fix to both skater and goalie stats methods

Testing Results:
- Successfully retrieves all 32 NHL teams with correct names
- Team lookup by abbreviation working correctly
- Division and conference filtering operational
- Player roster retrieval functional (28 players)
- Player stats aggregation working (verified with Sammy Blais)

All adapter methods now correctly transform NHL API responses to domain entities.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 22:33:44 -06:00
Michael Simard
6d8d51f698 Implement NHL API integration with nhlpy library
Added complete implementation of NHL API data adapters:

Player Adapter:
- get_player_by_id: Retrieves player info from career stats
- get_players_by_team: Fetches full team roster (forwards, defensemen, goalies)
- get_skater_stats: Aggregates current season skater statistics from game logs
- get_goalie_stats: Aggregates current season goalie statistics from game logs
- Data transformation utilities for roster and player data

Team Adapter:
- get_all_teams: Retrieves all NHL teams with division/conference info
- get_team_by_id: Looks up team by ID or abbreviation
- get_teams_by_division: Filters teams by division
- get_teams_by_conference: Filters teams by conference
- Data transformation for team entities

Technical Details:
- Corrected package name from nhl-api-py to nhlpy in requirements
- Implemented proper error handling with logging
- Dynamic season calculation based on current date
- Stats aggregation from game log data for accurate totals
- Proper type transformations between API responses and domain entities

Note: Player search functionality marked as not implemented due to API limitations

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 17:22:21 -06:00
Michael Simard
337a6377de Initial commit: CLEAN architecture foundation for fantasy hockey backend
Implemented CLEAN architecture with clear separation of concerns:
- Domain layer with entities (Player, Team, Stats, FantasyTeam) and repository interfaces
- Application layer with use case implementations
- Infrastructure layer with NHL API and Yahoo Fantasy API adapters
- Presentation layer with FastAPI configuration and dependency injection

Key features:
- Swappable data source adapters (NHL API, Yahoo Fantasy API)
- Repository pattern for data access abstraction
- Dependency injection for loose coupling
- FastAPI framework with async support
- PostgreSQL database configuration
- Environment-based configuration management

Technology stack: Python 3.11+, FastAPI, PostgreSQL, nhl-api-py, yfpy

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 17:13:58 -06:00