2015-05-22 09:13:52 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Controller\Api\Stations;
|
2015-05-22 09:13:52 +00:00
|
|
|
|
2019-08-07 04:33:55 +00:00
|
|
|
use App\Entity;
|
2019-08-09 15:00:21 +00:00
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
2020-06-26 20:22:53 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2019-04-07 08:40:55 +00:00
|
|
|
use OpenApi\Annotations as OA;
|
2019-08-07 04:33:55 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2015-05-22 09:13:52 +00:00
|
|
|
|
2021-12-12 11:01:53 +00:00
|
|
|
/**
|
|
|
|
* @OA\Get(path="/stations",
|
|
|
|
* operationId="getStations",
|
|
|
|
* tags={"Stations: General"},
|
|
|
|
* description="Returns a list of stations.",
|
|
|
|
* parameters={},
|
|
|
|
* @OA\Response(response=200, description="Success",
|
|
|
|
* @OA\JsonContent(type="array",
|
|
|
|
* @OA\Items(ref="#/components/schemas/Api_NowPlaying_Station")
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* @OA\Get(path="/station/{station_id}",
|
|
|
|
* operationId="getStation",
|
|
|
|
* tags={"Stations: General"},
|
|
|
|
* description="Return information about a single station.",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/station_id_required"),
|
|
|
|
* @OA\Response(response=200, description="Success",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Api_NowPlaying_Station")
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=404, description="Station not found")
|
|
|
|
* )
|
|
|
|
*/
|
2018-02-17 01:58:58 +00:00
|
|
|
class IndexController
|
2015-05-22 09:13:52 +00:00
|
|
|
{
|
2020-10-19 10:41:15 +00:00
|
|
|
public function __construct(
|
2021-04-23 05:24:12 +00:00
|
|
|
protected EntityManagerInterface $em,
|
|
|
|
protected Entity\ApiGenerator\StationApiGenerator $stationApiGenerator
|
2020-10-19 10:41:15 +00:00
|
|
|
) {
|
2017-12-09 17:29:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 15:00:21 +00:00
|
|
|
public function listAction(ServerRequest $request, Response $response): ResponseInterface
|
2015-05-22 09:13:52 +00:00
|
|
|
{
|
2018-08-19 10:40:05 +00:00
|
|
|
$stations_raw = $this->em->getRepository(Entity\Station::class)
|
|
|
|
->findBy(['is_enabled' => 1]);
|
2015-05-22 09:13:52 +00:00
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
$stations = [];
|
|
|
|
foreach ($stations_raw as $row) {
|
2017-05-29 10:47:22 +00:00
|
|
|
/** @var Entity\Station $row */
|
2020-10-19 10:41:15 +00:00
|
|
|
$api_row = ($this->stationApiGenerator)($row);
|
2019-08-09 15:00:21 +00:00
|
|
|
$api_row->resolveUrls($request->getRouter()->getBaseUrl());
|
2018-10-04 23:12:12 +00:00
|
|
|
|
2017-10-08 22:27:47 +00:00
|
|
|
if ($api_row->is_public) {
|
|
|
|
$stations[] = $api_row;
|
|
|
|
}
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2015-05-22 09:13:52 +00:00
|
|
|
|
2019-08-09 15:00:21 +00:00
|
|
|
return $response->withJson($stations);
|
2015-05-22 09:13:52 +00:00
|
|
|
}
|
2017-05-20 00:40:36 +00:00
|
|
|
|
2019-08-09 15:00:21 +00:00
|
|
|
public function indexAction(ServerRequest $request, Response $response): ResponseInterface
|
2017-05-20 00:40:36 +00:00
|
|
|
{
|
2020-04-02 11:30:00 +00:00
|
|
|
$station = $request->getStation();
|
|
|
|
|
2020-10-19 10:41:15 +00:00
|
|
|
$apiResponse = ($this->stationApiGenerator)($station);
|
2020-04-02 11:30:00 +00:00
|
|
|
$apiResponse->resolveUrls($request->getRouter()->getBaseUrl());
|
2018-10-04 23:12:12 +00:00
|
|
|
|
2020-04-02 11:30:00 +00:00
|
|
|
return $response->withJson($apiResponse);
|
2017-05-20 00:40:36 +00:00
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|