welcome back to dyb-tech

This commit is contained in:
Daniel Guzman
2024-05-18 02:28:01 +02:00
parent 9513cdba09
commit 9f30bc98c7
6149 changed files with 668407 additions and 0 deletions
@@ -0,0 +1,47 @@
<?php
namespace DMD\LaLigaApi\Service\Season\getAllSeasons;
use DMD\LaLigaApi\Dto\SeasonDto;
use DMD\LaLigaApi\Repository\SeasonRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class HandleGetAllSeason
{
public const PAGE_SIZE = 10;
public function __construct(
public EntityManagerInterface $entityManager,
public SeasonRepository $seasonRepository,
){}
public function __invoke(Request $request, int $page): JsonResponse
{
$seasonCollection = $this->seasonRepository->findBy([
'active' => true
],
limit: 10,
offset: ($page * self::PAGE_SIZE) - self::PAGE_SIZE
);
$seasonArray = [];
if (!is_null($seasonCollection))
{
foreach ($seasonCollection as $seasonObj)
{
$seasonDto = new SeasonDto();
$seasonDto->fillFromObject($seasonObj);
$seasonArray[] = $seasonDto->toArray();
}
}
return new JsonResponse(
data: [
'success' => true,
'seasons' => $seasonArray
],
status: Response::HTTP_OK
);
}
}