Add teams to response
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good Details

This commit is contained in:
Daniel Guzman 2024-07-25 02:04:46 +02:00
parent 58eb6141a8
commit 442e3e3248
2 changed files with 19 additions and 9 deletions

View File

@ -30,9 +30,14 @@ class SeasonDto
public function createSeasonArray(): array
{
$numberOfTeams = $this->numberOfTeams ?? 0;
$teamList = [];
if (!empty($this->teamDtoList))
{
$numberOfTeams = count($this->teamDtoList);
foreach ($this->teamDtoList as $teamDto)
{
$teamList[] = $teamDto->toArray();
}
}
return [
'id' => $this->id ?? null,
@ -42,6 +47,7 @@ class SeasonDto
'dateStart' => !empty($this->dateStart) ? $this->dateStart->format('Y-m-d'): null,
'leagueId' => $this->leagueId ?? null,
'leagueName' => $this->leagueName ?? null,
'teams' => $teamList,
'pointsPerWin' => $this->pointsPerWin ?? null,
'pointsPerDraw' => $this->pointsPerDraw ?? null,
'pointsPerLoss' => $this->pointsPerLoss ?? null,

View File

@ -58,11 +58,22 @@ class HandleCreateSeason
{
$this->createTeams($numberOfTeams, $seasonEntity, $seasonDto);
}
$this->entityManager->persist($seasonEntity);
$this->entityManager->flush();
$teamEntityList = $seasonEntity->getTeams();
$teamDtoList = [];
if (!empty($teamEntityList))
{
foreach ($teamEntityList as $teamEntity)
{
$teamDto = new TeamDto();
$teamDto->name = $teamEntity->getName();
$teamDto->id = $teamEntity->getId();
$teamDtoList[] = $teamDto;
}
}
$seasonDto->id = $seasonEntity->getId();
$seasonDto->teamDtoList = $teamDtoList;
return new JsonResponse(
data: [
'success' => true,
@ -78,18 +89,11 @@ class HandleCreateSeason
{
for ($i = 0; $i < $numberOfTeams; $i++)
{
$teamDto = new TeamDto();
$teamEntity = new Team();
$teamEntity->addSeason($seasonEntity);
$teamEntity->setName('Equipo '. $i+1);
$teamDto->name = $teamEntity->getName();
$teamDto->active = true;
$teamEntity->setActive(true);
$this->entityManager->persist($seasonEntity);
$this->entityManager->persist($teamEntity);
$this->entityManager->flush();
$teamDto->id = $teamEntity->getId();
$seasonDto->teamDtoList[] = $teamDto;
}
}
}