<?php
namespace App\Controller\Center;
use App\Entity\Station;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class StationController extends AbstractController
{
/**
* @Route("stations/city", name="getCity", methods={"GET","HEAD"})
*/
public function getCity(Request $request): Response
{
$stations = $this->getDoctrine()
->getRepository(Station::class)->getCity();
$station = array_map(function ($station) {
return [
"id" => $station->getId(),
"city" => $station->getCity(),
];
}, $stations);
return $this->json([
"stations" => $station,
"status" => 200
]);
}
/**
* @Route("stations/line", name="getLine", methods={"GET","HEAD"})
*/
public function getLine(Request $request): Response
{
$stations = $this->getDoctrine()
->getRepository(Station::class)->findByLine($request->get('city'));
$station = array_map(function ($station) {
return [
"id" => $station->getId(),
"city" => $station->getCity(),
"line" => $station->getLine(),
];
}, $stations);
return $this->json([
"Lines" => $station,
"status" => 200
]);
}
/**
* @Route("stations/name", name="getName", methods={"GET","HEAD"})
*/
public function getName(Request $request): Response
{
$stations = $this->getDoctrine()
->getRepository(Station::class)->findByName($request->get('line'));
$station = array_map(function ($station) {
return [
"id" => $station->getId(),
"city" => $station->getCity(),
"line" => $station->getLine(),
"name" => $station->getName(),
];
}, $stations);
return $this->json([
"Lines" => $station,
"status" => 200
]);
}
}