src/Controller/Center/StationController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Center;
  3. use App\Entity\Station;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. class StationController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("stations/city", name="getCity", methods={"GET","HEAD"})
  12.      */
  13.     public function getCity(Request $request): Response
  14.     {
  15.         $stations $this->getDoctrine()
  16.             ->getRepository(Station::class)->getCity();
  17.             $station array_map(function ($station) {
  18.                 return [
  19.             "id" => $station->getId(),
  20.             "city" => $station->getCity(),
  21.              ];
  22.     
  23.          }, $stations);
  24.     
  25.             return $this->json([
  26.                 "stations" => $station,
  27.                 "status" => 200
  28.             ]);
  29.     }
  30.      /**
  31.      * @Route("stations/line", name="getLine", methods={"GET","HEAD"})
  32.      */
  33.     public function getLine(Request $request): Response
  34.     {
  35.         $stations $this->getDoctrine()
  36.             ->getRepository(Station::class)->findByLine($request->get('city'));
  37.             $station array_map(function ($station) {
  38.                 return [
  39.             "id" => $station->getId(),
  40.             "city" => $station->getCity(),
  41.             "line" => $station->getLine(),
  42.              ];
  43.     
  44.          }, $stations);
  45.     
  46.             return $this->json([
  47.                 "Lines" => $station,
  48.                 "status" => 200
  49.             ]);
  50.     }
  51.     
  52.      /**
  53.      * @Route("stations/name", name="getName", methods={"GET","HEAD"})
  54.      */
  55.     public function getName(Request $request): Response
  56.     {
  57.         $stations $this->getDoctrine()
  58.             ->getRepository(Station::class)->findByName($request->get('line'));
  59.             $station array_map(function ($station) {
  60.                 return [
  61.             "id" => $station->getId(),
  62.             "city" => $station->getCity(),
  63.             "line" => $station->getLine(),
  64.             "name" => $station->getName(),
  65.              ];
  66.     
  67.          }, $stations);
  68.     
  69.             return $this->json([
  70.                 "Lines" => $station,
  71.                 "status" => 200
  72.             ]);
  73.     }
  74. }