Skip to content

Instantly share code, notes, and snippets.

@glaphire
Created August 11, 2020 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaphire/47bf944663e677954e78932ab081e86c to your computer and use it in GitHub Desktop.
Save glaphire/47bf944663e677954e78932ab081e86c to your computer and use it in GitHub Desktop.
<?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