Fix get season teams
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good Details

This commit is contained in:
Daniel Guzman 2024-07-25 00:36:59 +02:00
parent 4819033a26
commit 8932feca8b
4 changed files with 22 additions and 14 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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");
}
}
}

View File

@ -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';