Add Get Season By ID
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good
Details
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b1a3b47aaf
commit
4819033a26
|
|
@ -1,3 +1,2 @@
|
||||||
\vendor
|
vendor/
|
||||||
\var
|
var/
|
||||||
/var
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use DMD\LaLigaApi\Service\Season\createGameCalendar\HandleCreateGameCalendarRequ
|
||||||
use DMD\LaLigaApi\Service\Season\createSeason\HandleCreateSeason;
|
use DMD\LaLigaApi\Service\Season\createSeason\HandleCreateSeason;
|
||||||
use DMD\LaLigaApi\Service\Season\getAllFacilities\HandleGetAllFacilities;
|
use DMD\LaLigaApi\Service\Season\getAllFacilities\HandleGetAllFacilities;
|
||||||
use DMD\LaLigaApi\Service\Season\getAllTeams\HandleGetAllTeams;
|
use DMD\LaLigaApi\Service\Season\getAllTeams\HandleGetAllTeams;
|
||||||
|
use DMD\LaLigaApi\Service\Season\getSeasonById\HandleGetSeasonById;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
@ -21,6 +22,12 @@ class SeasonController extends AbstractController
|
||||||
return $handleCreateSeason($request, $leagueId);
|
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'])]
|
#[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
|
public function addTeam(Request $request, HandleAddTeamList $handleAddTeam, int $leagueId, int $seasonId): JsonResponse
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace DMD\LaLigaApi\Service\Season\getSeasonById;
|
||||||
|
|
||||||
use DMD\LaLigaApi\Dto\LeagueDto;
|
use DMD\LaLigaApi\Dto\LeagueDto;
|
||||||
use DMD\LaLigaApi\Dto\SeasonDto;
|
use DMD\LaLigaApi\Dto\SeasonDto;
|
||||||
|
use DMD\LaLigaApi\Repository\LeagueRepository;
|
||||||
use DMD\LaLigaApi\Repository\SeasonRepository;
|
use DMD\LaLigaApi\Repository\SeasonRepository;
|
||||||
use DMD\LaLigaApi\Repository\UserRepository;
|
use DMD\LaLigaApi\Repository\UserRepository;
|
||||||
use DMD\LaLigaApi\Service\League\LeagueFactory;
|
use DMD\LaLigaApi\Service\League\LeagueFactory;
|
||||||
|
|
@ -18,13 +19,18 @@ class HandleGetSeasonById
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public EntityManagerInterface $entityManager,
|
public EntityManagerInterface $entityManager,
|
||||||
|
public LeagueRepository $leagueRepository,
|
||||||
public SeasonRepository $seasonRepository,
|
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);
|
$leagueEntity = $this->leagueRepository->find($leagueId);
|
||||||
if (is_null($seasonObj))
|
$seasonEntity = $this->seasonRepository->findOneBy([
|
||||||
|
'id' => $seasonId,
|
||||||
|
'league' => $leagueEntity,
|
||||||
|
]);
|
||||||
|
if (is_null($seasonEntity))
|
||||||
{
|
{
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
Response::HTTP_NOT_FOUND,
|
Response::HTTP_NOT_FOUND,
|
||||||
|
|
@ -32,7 +38,7 @@ class HandleGetSeasonById
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$seasonDto = new SeasonDto();
|
$seasonDto = new SeasonDto();
|
||||||
$seasonDto->fillFromEntity($seasonObj);
|
$seasonDto->fillFromEntity($seasonEntity);
|
||||||
return new JsonResponse(
|
return new JsonResponse(
|
||||||
data: [
|
data: [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue