From a9581195344be9e28e6df93cbf73d9f30434ecdf Mon Sep 17 00:00:00 2001 From: Daniel Guzman Date: Sun, 2 Jun 2024 11:56:15 +0200 Subject: [PATCH] Change response format of league object --- src/Dto/LeagueDto.php | 15 +++++++++++++++ .../League/createLeague/HandleCreateLeague.php | 2 +- .../League/getAllLeagues/HandleGetAllLeagues.php | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Dto/LeagueDto.php b/src/Dto/LeagueDto.php index f1f659b2..98cc2167 100644 --- a/src/Dto/LeagueDto.php +++ b/src/Dto/LeagueDto.php @@ -38,6 +38,7 @@ class LeagueDto return [ 'id' => $this->id ?? null, 'name' => $this->name ?? null, + 'city' => $this->city ?? null, 'logo' => $this->logo ?? null, 'description' => $this->description ?? null, 'pointsPerWin' => $this->pointsPerWin ?? null, @@ -53,6 +54,20 @@ class LeagueDto ]; } + public function getAllLeaguesArray(): array + { + $seasonCount = !empty($this->seasonDtoList) ? count($this->seasonDtoList) : 0; + return [ + 'id' => $this->id ?? '', + 'name' => $this->name ?? '', + 'city' => $this->city ?? '', + 'logo' => $this->logo ?? '', + 'description' => $this->description ?? '', + 'isPublic' => $this->isPublic ?? '', + 'createdAt' => !empty($this->createdAt) ? $this->createdAt->format('Y-m-d H:i:s') : '', + ]; + } + public function fillFromArray(array $dataList): void { if (isset($dataList['id'])) diff --git a/src/Service/League/createLeague/HandleCreateLeague.php b/src/Service/League/createLeague/HandleCreateLeague.php index 18aa9835..67d2fa86 100644 --- a/src/Service/League/createLeague/HandleCreateLeague.php +++ b/src/Service/League/createLeague/HandleCreateLeague.php @@ -42,8 +42,8 @@ class HandleCreateLeague $leagueDto = new LeagueDto(); $leagueDto->fillFromArray($request->toArray()); $leagueDto->validate(); + $leagueDto->active = true; $leagueEntity = $this->leagueFactory::create($leagueDto); - $leagueEntity->setActive(true); $this->entityManager->persist($leagueEntity); $this->entityManager->flush(); diff --git a/src/Service/League/getAllLeagues/HandleGetAllLeagues.php b/src/Service/League/getAllLeagues/HandleGetAllLeagues.php index 3f5979d0..5ebad8e7 100644 --- a/src/Service/League/getAllLeagues/HandleGetAllLeagues.php +++ b/src/Service/League/getAllLeagues/HandleGetAllLeagues.php @@ -34,7 +34,7 @@ class HandleGetAllLeagues { $leagueDto = new LeagueDto(); $leagueDto->fillFromObject($leagueObj); - $leagueArray[] = $leagueDto->toArray(); + $leagueArray[] = $leagueDto->getAllLeaguesArray(); } } return new JsonResponse(