Get all facilities
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
08a43cb760
commit
017caf49b0
|
|
@ -25,9 +25,14 @@ class SeasonController extends AbstractController
|
|||
return $handleAddTeam($request, $leagueId, $seasonId);
|
||||
}
|
||||
#[Route('/api/league/{leagueId}/season/{seasonId}/facilities/create', name: 'app_create_facilities', methods: ['POST'])]
|
||||
public function createFacilities(Request $request, HandleCreateFacilities $handleAddTeam, int $leagueId, int $seasonId): JsonResponse
|
||||
public function createFacilities(Request $request, HandleCreateFacilities $handleCreateFacilities, int $leagueId, int $seasonId): JsonResponse
|
||||
{
|
||||
return $handleAddTeam($request, $leagueId, $seasonId);
|
||||
return $handleCreateFacilities($request, $leagueId, $seasonId);
|
||||
}
|
||||
#[Route('/api/league/{leagueId}/season/{seasonId}/facilities/', name: 'app_get_all_facilities', methods: ['GET'])]
|
||||
public function getAllFacilities(Request $request, HandleGetAllFacilities $handleAddTeam, int $leagueId, int $seasonId): JsonResponse
|
||||
{
|
||||
return $handleGetAllFacilities($request, $leagueId, $seasonId);
|
||||
}
|
||||
|
||||
#[Route('/api/league/{leagueId}/season/{seasonId}/calendar', name: 'app_create_calendar', methods: ['POST'])]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Service\Season\getAllFacilities;
|
||||
|
||||
use DMD\LaLigaApi\Dto\FacilityDto;
|
||||
use DMD\LaLigaApi\Dto\SeasonDto;
|
||||
use DMD\LaLigaApi\Entity\Season;
|
||||
use DMD\LaLigaApi\Repository\FacilityRepository;
|
||||
use DMD\LaLigaApi\Repository\SeasonRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class HandleGetAllFacilities
|
||||
{
|
||||
public const PAGE_SIZE = 10;
|
||||
|
||||
public function __construct(
|
||||
public EntityManagerInterface $entityManager,
|
||||
public FacilityRepository $facilityRepository,
|
||||
public SeasonRepository $seasonRepository
|
||||
){}
|
||||
|
||||
public function __invoke(Request $request, int $leagueId, int $seasonId): JsonResponse
|
||||
{
|
||||
$seasonEntity = $this->seasonRepository->find($seasonId);
|
||||
if (!$seasonEntity instanceof Season)
|
||||
{
|
||||
throw new HttpException(Response::HTTP_NOT_FOUND, 'Season not found, check id');
|
||||
}
|
||||
$facilityCollection = $this->facilityRepository->findBy([
|
||||
'season' => $seasonEntity,
|
||||
'active' => true
|
||||
]);
|
||||
$facilityArray = [];
|
||||
if (!is_null($facilityCollection))
|
||||
{
|
||||
foreach ($facilityCollection as $facilityObj)
|
||||
{
|
||||
$facilityDto = new FacilityDto();
|
||||
$facilityDto->fillFromObject($facilityObj);
|
||||
$facilityArray[] = $facilityDto->createFacilityArray();
|
||||
}
|
||||
}
|
||||
return new JsonResponse(
|
||||
data: [
|
||||
'success' => true,
|
||||
'facilities' => $facilityArray
|
||||
],
|
||||
status: Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue