feat: get lolesport official api season

This commit is contained in:
Aymeric GUERACAGUE 2026-01-02 17:51:44 +01:00
parent 2a17cd082c
commit 350f134e23
Signed by: Superkooka
GPG Key ID: F78F2B172E894865
8 changed files with 2952 additions and 6 deletions

View File

@ -29,7 +29,16 @@ interface LolEsportOfficialAPIEngine
*/ */
public function getLeagues(); public function getLeagues();
public function getSeasons(); // "Tournament" /**
* @param string $leagueId
* @return array<{
* id: string,
* slug: string,
* startDate: \DateTimeImmutable,
* endDate: \DateTimeImmutable,
* }>
*/
public function getSeasons(string $leagueId); // "Tournament"
public function getSchedules(); public function getSchedules();
} }

View File

@ -0,0 +1,16 @@
<?php
namespace App\Application\ReadModel;
readonly class Season
{
public function __construct(
public string $id,
public string $providerId,
public string $providerSeasonId,
public int $year,
public string $kind,
public string $leagueId,
) {
}
}

View File

@ -4,15 +4,26 @@ namespace App\Application\UseCase\LeagueOfLegends;
use App\Application\LolEsportOfficialAPI\LolEsportOfficialAPIEngine; use App\Application\LolEsportOfficialAPI\LolEsportOfficialAPIEngine;
use App\Application\ReadModel\League as LeagueRM; use App\Application\ReadModel\League as LeagueRM;
use App\Application\ReadModel\Season as SeasonRM;
use App\Application\ReadModel\Provider as ProviderRM; use App\Application\ReadModel\Provider as ProviderRM;
use App\Application\ReadModel\Team as TeamRM; use App\Application\ReadModel\Team as TeamRM;
use App\Domain\Entity\League; use App\Domain\Entity\League;
use App\Domain\Entity\Provider; use App\Domain\Entity\Provider;
use App\Domain\Entity\Season;
use App\Domain\Entity\Team; use App\Domain\Entity\Team;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
class FetchLolEsportOfficialAPISchedule class FetchLolEsportOfficialAPISchedule
{ {
const array ENABLED_LEAGUE = [
'98767975604431411', // Worlds
'98767991325878492', // MSI
'113464388705111224', // First Stand
'98767991302996019', // LEC
'100695891328981122', // EMEA Masters
'105266103462388553', // LFL
]; // should not be here
public function __construct( public function __construct(
private readonly LolEsportOfficialAPIEngine $lolEsportOfficialAPIEngine, private readonly LolEsportOfficialAPIEngine $lolEsportOfficialAPIEngine,
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
@ -71,7 +82,7 @@ class FetchLolEsportOfficialAPISchedule
} }
foreach ($lolEsportOfficialAPILeagues as $league) { foreach ($lolEsportOfficialAPILeagues as $league) {
if (!isset($leaguesRMWithId[$league['id']])) { if (!isset($leaguesRMWithId[$league['id']]) && in_array($league['id'], self::ENABLED_LEAGUE)) {
// Create Team // Create Team
$leagueEntity = new League(); $leagueEntity = new League();
$leagueEntity->create( $leagueEntity->create(
@ -89,6 +100,34 @@ class FetchLolEsportOfficialAPISchedule
// Fetch Season (Tournament). Need to be maped to a league from name if fetch all, can be fetch by league // Fetch Season (Tournament). Need to be maped to a league from name if fetch all, can be fetch by league
// add endDate // add endDate
$seasonsRM = $this->entityManager->getRepository(SeasonRM::class)->findBy(['providerId' => $providerRM->id]);
$seasonsRMWithId = [];
foreach ($seasonsRM as $season) {
$seasonsRMWithId[$season->providerSeasonId] = $season;
}
$leaguesRM = $this->entityManager->getRepository(LeagueRM::class)->findBy(['providerId' => $providerRM->id]);
foreach ($leaguesRM as $league) {
$lolEsportOfficialAPISeason = $this->lolEsportOfficialAPIEngine->getSeasons($league->providerLeagueId);
foreach ($lolEsportOfficialAPISeason as $season) {
if(!isset($seasonsRMWithId[$season['id']])) {
$leagueEntity = $this->entityManager->getRepository(League::class)->find($league->id);
$seasonEntity = new Season();
$seasonEntity->create(
$provider,
$season['id'],
$leagueEntity,
'REG',
(int) (new \DateTimeImmutable($season['endDate']))->format('Y'),
);
$this->entityManager->persist($seasonEntity);
}
}
}
// Fetch Match Schedule // Fetch Match Schedule
// paginated. can be by league or global // paginated. can be by league or global

View File

@ -33,9 +33,17 @@ class FakeLolEsportOfficialAPIEngine implements LolEsportOfficialAPIEngine
], $fake_lolesport_official_api_lol_leagues['data']['leagues']); ], $fake_lolesport_official_api_lol_leagues['data']['leagues']);
} }
public function getSeasons() public function getSeasons(string $leagueId)
{ {
// TODO: Implement getSeasons() method. $fake_lolesport_official_api_lol_seasons= json_decode(file_get_contents(__DIR__ . '/Fixtures/lolesport_official_api_lol_seasons_02_01_2026.json'), true);
return array_map(fn ($season) => [
'id' => $season['id'],
'slug' => $season['slug'],
'startDate' => $season['startDate'],
'endDate' => $season['endDate'],
], $fake_lolesport_official_api_lol_seasons['data']['leagues'][$leagueId]['tournaments'] ?? throw new \Exception('league id not found'));
} }
public function getSchedules() public function getSchedules()

View File

@ -16,7 +16,7 @@ class HTTPLolEsportOfficialAPIEngine implements LolEsportOfficialAPIEngine
// TODO: Implement getLeagues() method. // TODO: Implement getLeagues() method.
} }
public function getSeasons() public function getSeasons(string $leagueId)
{ {
// TODO: Implement getSeasons() method. // TODO: Implement getSeasons() method.
} }

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
$builder = new Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder($metadata);
$builder
->setReadOnly()
->setTable('season')
;
$builder
->createField('id', 'uuid')
->nullable(false)
->makePrimaryKey()
->build();
$builder
->createField('providerId', 'uuid')
->columnName('provider_id')
->nullable(false)
->build();
$builder
->createField('providerSeasonId', 'string')
->columnName('provider_season_id')
->nullable(false)
->build();
$builder
->createField('year', 'integer')
->nullable(false)
->build();
$builder
->createField('kind', 'string')
->nullable(false)
->build();
$builder
->createField('leagueId', 'string')
->columnName('league_id')
->nullable(false)
->build();

View File

@ -15,7 +15,7 @@ $builder
->build(); ->build();
$builder $builder
->createField('providerSeasonId', 'uuid') ->createField('providerSeasonId', 'string')
->columnName('provider_season_id') ->columnName('provider_season_id')
->nullable(false) ->nullable(false)
->build(); ->build();