diff --git a/src/Application/SportRadar/SportRadarEngine.php b/src/Application/SportRadar/SportRadarEngine.php index 13df518..7ff45c6 100644 --- a/src/Application/SportRadar/SportRadarEngine.php +++ b/src/Application/SportRadar/SportRadarEngine.php @@ -4,7 +4,30 @@ declare(strict_types=1); namespace App\Application\SportRadar; +use App\Domain\Enum\ENHLSeasonType; + interface SportRadarEngine { - public function getNHLSchedule(): void; + /** + * @return array{ + * league: array{ + * providerId: string, + * name: string, + * alias: string, + * }, + * season: array{ + * providerId: string, + * year: int, + * type: string, + * }, + * games: array + * } + */ + public function getNHLSchedule(int $year, ENHLSeasonType $seasonType): array; } diff --git a/src/Application/UseCase/GetNHLMatch.php b/src/Application/UseCase/GetNHLMatch.php index ccb7933..353da79 100644 --- a/src/Application/UseCase/GetNHLMatch.php +++ b/src/Application/UseCase/GetNHLMatch.php @@ -4,10 +4,18 @@ declare(strict_types=1); namespace App\Application\UseCase; +use App\Application\SportRadar\SportRadarEngine; +use App\Domain\Enum\ENHLSeasonType; + class GetNHLMatch { + public function __construct( + private readonly SportRadarEngine $sportRadarEngine, + ) { + } + public function __invoke(GetNHLMatchRequest $request): void { - dd($request->type); + dd($this->sportRadarEngine->getNHLSchedule($request->year, ENHLSeasonType::from($request->type))['games'][0]); } } diff --git a/src/Application/UseCase/GetNHLMatchRequest.php b/src/Application/UseCase/GetNHLMatchRequest.php index b7aceb4..4c2951e 100644 --- a/src/Application/UseCase/GetNHLMatchRequest.php +++ b/src/Application/UseCase/GetNHLMatchRequest.php @@ -7,6 +7,7 @@ namespace App\Application\UseCase; class GetNHLMatchRequest { public function __construct( + public readonly int $year, public readonly string $type, ) { } diff --git a/src/Domain/Enum/ENHLSeasonType.php b/src/Domain/Enum/ENHLSeasonType.php new file mode 100644 index 0000000..3edafbe --- /dev/null +++ b/src/Domain/Enum/ENHLSeasonType.php @@ -0,0 +1,12 @@ +commandBus->ask(new GetNHLMatchRequest('REG')); + $this->commandBus->ask(new GetNHLMatchRequest(2025, 'REG')); return Command::SUCCESS; } diff --git a/src/Infrastructure/SportRadar/HTTPSportRadarEngine.php b/src/Infrastructure/SportRadar/HTTPSportRadarEngine.php index 23baf01..f4286f3 100644 --- a/src/Infrastructure/SportRadar/HTTPSportRadarEngine.php +++ b/src/Infrastructure/SportRadar/HTTPSportRadarEngine.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Infrastructure\SportRadar; use App\Application\SportRadar\SportRadarEngine; +use App\Domain\Enum\ENHLSeasonType; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -25,10 +26,29 @@ class HTTPSportRadarEngine implements SportRadarEngine ); } - public function getNHLSchedule(): void + public function getNHLSchedule(int $year, ENHLSeasonType $seasonType): array { - $response = $this->client->request('GET', 'https://api.sportradar.com/nhl/trial/v7/en/games/2025/REG/schedule.json'); + $response = $this->client->request('GET', sprintf('https://api.sportradar.com/nhl/trial/v7/en/games/%s/%s/schedule.json', $year, $seasonType->value)); + $response = json_decode($response->getContent(), true); - // return ['a']; + return [ + 'league' => [ + 'providerId' => $response['league']['id'], + 'name' => $response['league']['name'], + 'alias' => $response['league']['alias'], + ], + 'season' => [ + 'providerId' => $response['season']['id'], + 'year' => $response['season']['year'], + 'type' => ENHLSeasonType::from($response['season']['type']), + ], + 'games' => array_map(fn ($game) => [ + 'providerId' => $game['id'], + 'scheduled' => new \DateTimeImmutable($game['scheduled']), + 'homeTeamProviderId' => $game['home']['id'], + 'awayTeamProviderId' => $game['away']['id'], + 'venueArena' => $game['venue']['name'], + ], $response['games']), + ]; } }