feat: HTTPSportRadarEngine

Signed-off-by: Superkooka <aymeric.gueracague@gmail.com>
This commit is contained in:
Aymeric GUERACAGUE 2025-12-20 19:05:31 +01:00
parent 7e2c6101ba
commit 004a0a201f
Signed by: Superkooka
GPG Key ID: F78F2B172E894865
6 changed files with 70 additions and 6 deletions

View File

@ -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<array{
* providerId: string,
* scheduled: \DateTimeImmutable,
* homeTeamProviderId: string,
* awayTeamProviderId: string,
* venueArena: string,
* }>
* }
*/
public function getNHLSchedule(int $year, ENHLSeasonType $seasonType): array;
}

View File

@ -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]);
}
}

View File

@ -7,6 +7,7 @@ namespace App\Application\UseCase;
class GetNHLMatchRequest
{
public function __construct(
public readonly int $year,
public readonly string $type,
) {
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace App\Domain\Enum;
enum ENHLSeasonType: string
{
case PRE_SEASON = 'PRE';
case REGULAR_SEASON = 'REG';
case POST_SEASON = 'PST';
}

View File

@ -17,7 +17,7 @@ class GetNHLScheduleCommand
public function __invoke(): int
{
$this->commandBus->ask(new GetNHLMatchRequest('REG'));
$this->commandBus->ask(new GetNHLMatchRequest(2025, 'REG'));
return Command::SUCCESS;
}

View File

@ -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']),
];
}
}