Created
August 11, 2020 18:20
-
-
Save glaphire/47bf944663e677954e78932ab081e86c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use App\Entity\NearEarthObject; | |
use App\Pagination\PaginationFactory; | |
use App\Repository\NearEarthObjectRepository; | |
use Doctrine\ORM\EntityManagerInterface; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Routing\Annotation\Route; | |
class NearEarthObjectController extends AbstractController | |
{ | |
private EntityManagerInterface $entityManager; | |
/** | |
* @var PaginationFactory | |
*/ | |
private $paginationFactory; | |
public function __construct(EntityManagerInterface $entityManager, PaginationFactory $paginationFactory) | |
{ | |
$this->entityManager = $entityManager; | |
$this->paginationFactory = $paginationFactory; | |
} | |
/** | |
* @Route("/neo/hazardous", name="neo_hazardous", methods={"GET"}) | |
*/ | |
public function hazardousAction(Request $request) | |
{ | |
/** | |
* @var NearEarthObjectRepository $nearEarthObjectRepository | |
*/ | |
$nearEarthObjectRepository = $this | |
->entityManager | |
->getRepository(NearEarthObject::class); | |
//TODO: add getting is_hazardous=1 | |
$queryBuilder = $nearEarthObjectRepository->findAllQueryBuilder(); | |
$paginatedCollection = $this | |
->paginationFactory | |
->createCollection($queryBuilder, $request, 'neo_hazardous'); | |
return new JsonResponse($paginatedCollection, 200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment