welcome back to dyb-tech
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user