Add Get Season By ID
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good Details

This commit is contained in:
Daniel Guzman 2024-07-25 00:17:37 +02:00
parent b1a3b47aaf
commit 4819033a26
3 changed files with 19 additions and 7 deletions

5
.gitignore vendored
View File

@ -1,3 +1,2 @@
\vendor
\var
/var
vendor/
var/

View File

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

View File

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