From 8932feca8b8f5b6ec8986d0c5b327725565e2384 Mon Sep 17 00:00:00 2001 From: Daniel Guzman Date: Thu, 25 Jul 2024 00:36:59 +0200 Subject: [PATCH] Fix get season teams --- src/Controller/SeasonController.php | 6 ++--- ...tAllSeason.php => HandleGetAllSeasons.php} | 2 +- ...tAllTeams.php => HandleGetSeasonTeams.php} | 26 ++++++++++++------- ...igaApi_KernelDevDebugContainer.preload.php | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) rename src/Service/Season/getAllSeasons/{HandleGetAllSeason.php => HandleGetAllSeasons.php} (98%) rename src/Service/Season/getAllTeams/{HandleGetAllTeams.php => HandleGetSeasonTeams.php} (78%) diff --git a/src/Controller/SeasonController.php b/src/Controller/SeasonController.php index 7086c76e..b3935ff0 100644 --- a/src/Controller/SeasonController.php +++ b/src/Controller/SeasonController.php @@ -7,7 +7,7 @@ use DMD\LaLigaApi\Service\Season\createFacilities\HandleCreateFacilities; use DMD\LaLigaApi\Service\Season\createGameCalendar\HandleCreateGameCalendarRequest; use DMD\LaLigaApi\Service\Season\createSeason\HandleCreateSeason; use DMD\LaLigaApi\Service\Season\getAllFacilities\HandleGetAllFacilities; -use DMD\LaLigaApi\Service\Season\getAllTeams\HandleGetAllTeams; +use DMD\LaLigaApi\Service\Season\getAllTeams\HandleGetSeasonTeams; use DMD\LaLigaApi\Service\Season\getSeasonById\HandleGetSeasonById; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -33,8 +33,8 @@ class SeasonController extends AbstractController { return $handleAddTeam($request, $leagueId, $seasonId); } - #[Route('/api/league/{leagueId}/season/{seasonId}/team', name: 'app_get_all_teams', methods: ['GET'])] - public function getAllTeam(Request $request, HandleGetAllTeams $handleGetAllTeams, int $leagueId, int $seasonId): JsonResponse + #[Route('/api/league/{leagueId}/season/{seasonId}/team', name: 'app_get_season_teams', methods: ['GET'])] + public function getSeasonTeams(Request $request, HandleGetSeasonTeams $handleGetAllTeams, int $leagueId, int $seasonId): JsonResponse { return $handleGetAllTeams($request, $leagueId, $seasonId); } diff --git a/src/Service/Season/getAllSeasons/HandleGetAllSeason.php b/src/Service/Season/getAllSeasons/HandleGetAllSeasons.php similarity index 98% rename from src/Service/Season/getAllSeasons/HandleGetAllSeason.php rename to src/Service/Season/getAllSeasons/HandleGetAllSeasons.php index 5ad2d26c..773f7626 100644 --- a/src/Service/Season/getAllSeasons/HandleGetAllSeason.php +++ b/src/Service/Season/getAllSeasons/HandleGetAllSeasons.php @@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -class HandleGetAllSeason +class HandleGetAllSeasons { public const PAGE_SIZE = 10; diff --git a/src/Service/Season/getAllTeams/HandleGetAllTeams.php b/src/Service/Season/getAllTeams/HandleGetSeasonTeams.php similarity index 78% rename from src/Service/Season/getAllTeams/HandleGetAllTeams.php rename to src/Service/Season/getAllTeams/HandleGetSeasonTeams.php index 6eea70a5..ae2f5441 100644 --- a/src/Service/Season/getAllTeams/HandleGetAllTeams.php +++ b/src/Service/Season/getAllTeams/HandleGetSeasonTeams.php @@ -2,6 +2,8 @@ namespace DMD\LaLigaApi\Service\Season\getAllTeams; +use DMD\LaLigaApi\Entity\League; +use DMD\LaLigaApi\Entity\Season; use DMD\LaLigaApi\Repository\LeagueRepository; use DMD\LaLigaApi\Repository\SeasonRepository; use DMD\LaLigaApi\Repository\TeamRepository; @@ -11,7 +13,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; -class HandleGetAllTeams +class HandleGetSeasonTeams { public function __construct( public TeamRepository $teamRepository, @@ -29,14 +31,8 @@ class HandleGetAllTeams 'id' => $seasonId, 'league' => $leagueEntity ]); - if (is_null($seasonEntity)) - { - throw new HttpException(Response::HTTP_NOT_FOUND, "Season not found"); - } - $teamEntityCollection = $this->teamRepository->findBy([ - 'leagueId' => $leagueId, - 'active' => true - ]); + $this->validateRequest($leagueEntity, $seasonEntity); + $teamEntityCollection = $seasonEntity?->getTeams(); if (empty($teamEntityCollection)) { return new JsonResponse([ @@ -56,4 +52,16 @@ class HandleGetAllTeams ], Response::HTTP_OK ); } + + private function validateRequest(?League $leagueEntity, ?Season $seasonEntity): void + { + if (is_null($leagueEntity)) + { + throw new HttpException(Response::HTTP_NOT_FOUND, "League not found"); + } + if (is_null($seasonEntity)) + { + throw new HttpException(Response::HTTP_NOT_FOUND, "Season not found"); + } + } } \ No newline at end of file diff --git a/var/cache/dev/DMD_LaLigaApi_KernelDevDebugContainer.preload.php b/var/cache/dev/DMD_LaLigaApi_KernelDevDebugContainer.preload.php index 8bc58a45..97d08f96 100644 --- a/var/cache/dev/DMD_LaLigaApi_KernelDevDebugContainer.preload.php +++ b/var/cache/dev/DMD_LaLigaApi_KernelDevDebugContainer.preload.php @@ -265,7 +265,7 @@ $classes[] = 'DMD\LaLigaApi\Service\Season\createGameCalendar\HandleCreateGameCa $classes[] = 'DMD\LaLigaApi\Service\Season\createSeason\HandleCreateSeason'; $classes[] = 'DMD\LaLigaApi\Service\Season\SeasonFactory'; $classes[] = 'DMD\LaLigaApi\Service\Season\getAllFacilities\HandleGetAllFacilities'; -$classes[] = 'DMD\LaLigaApi\Service\Season\getAllTeams\HandleGetAllTeams'; +$classes[] = 'DMD\LaLigaApi\Service\Season\getAllTeams\HandleGetSeasonTeams'; $classes[] = 'DMD\LaLigaApi\Service\User\Handlers\UserSaver'; $classes[] = 'DMD\LaLigaApi\Service\User\Handlers\delete\HandleDeleteUser'; $classes[] = 'DMD\LaLigaApi\Service\User\Handlers\getNotifications\HandleGetNotifications';