diff --git a/.gitignore b/.gitignore index 48695641..5a047ca3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -\vendor -\var -/var +vendor/ +var/ diff --git a/src/Controller/SeasonController.php b/src/Controller/SeasonController.php index ac677beb..7086c76e 100644 --- a/src/Controller/SeasonController.php +++ b/src/Controller/SeasonController.php @@ -8,6 +8,7 @@ use DMD\LaLigaApi\Service\Season\createGameCalendar\HandleCreateGameCalendarRequ 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\getSeasonById\HandleGetSeasonById; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -21,6 +22,12 @@ class SeasonController extends AbstractController return $handleCreateSeason($request, $leagueId); } + #[Route('/api/league/{leagueId}/season/{seasonId}', name: 'app_get_season_by_id', methods: ['GET'])] + public function getSeasonById(Request $request, HandleGetSeasonById $handleGetSeasonById, int $leagueId, int $seasonId): JsonResponse + { + return $handleGetSeasonById($request, $leagueId, $seasonId); + } + #[Route('/api/league/{leagueId}/season/{seasonId}/team', name: 'app_add_team', methods: ['POST'])] public function addTeam(Request $request, HandleAddTeamList $handleAddTeam, int $leagueId, int $seasonId): JsonResponse { diff --git a/src/Service/Season/getSeasonById/HandleGetSeasonById.php b/src/Service/Season/getSeasonById/HandleGetSeasonById.php index 1ecbb86b..e5bb8f37 100644 --- a/src/Service/Season/getSeasonById/HandleGetSeasonById.php +++ b/src/Service/Season/getSeasonById/HandleGetSeasonById.php @@ -4,6 +4,7 @@ namespace DMD\LaLigaApi\Service\Season\getSeasonById; use DMD\LaLigaApi\Dto\LeagueDto; use DMD\LaLigaApi\Dto\SeasonDto; +use DMD\LaLigaApi\Repository\LeagueRepository; use DMD\LaLigaApi\Repository\SeasonRepository; use DMD\LaLigaApi\Repository\UserRepository; use DMD\LaLigaApi\Service\League\LeagueFactory; @@ -18,13 +19,18 @@ class HandleGetSeasonById { public function __construct( public EntityManagerInterface $entityManager, + public LeagueRepository $leagueRepository, public SeasonRepository $seasonRepository, ){} - public function __invoke(Request $request, int $seasonId): JsonResponse + public function __invoke(Request $request, int $leagueId, int $seasonId): JsonResponse { - $seasonObj = $this->seasonRepository->find($seasonId); - if (is_null($seasonObj)) + $leagueEntity = $this->leagueRepository->find($leagueId); + $seasonEntity = $this->seasonRepository->findOneBy([ + 'id' => $seasonId, + 'league' => $leagueEntity, + ]); + if (is_null($seasonEntity)) { throw new HttpException( Response::HTTP_NOT_FOUND, @@ -32,7 +38,7 @@ class HandleGetSeasonById ); } $seasonDto = new SeasonDto(); - $seasonDto->fillFromEntity($seasonObj); + $seasonDto->fillFromEntity($seasonEntity); return new JsonResponse( data: [ 'success' => true,