2018-12-12 09:01:03 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-12-12 09:01:03 +00:00
|
|
|
namespace App\Controller\Api\Stations;
|
|
|
|
|
|
|
|
use App;
|
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;
|
2019-09-04 18:00:51 +00:00
|
|
|
use InvalidArgumentException;
|
2019-08-07 04:33:55 +00:00
|
|
|
use OpenApi\Annotations as OA;
|
2018-12-12 09:01:03 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2018-12-23 23:26:15 +00:00
|
|
|
use Symfony\Component\Serializer\Serializer;
|
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
2018-12-12 09:01:03 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
/**
|
2021-12-12 11:01:53 +00:00
|
|
|
* @OA\Get(path="/station/{station_id}/queue",
|
|
|
|
* operationId="getQueue",
|
|
|
|
* tags={"Stations: Queue"},
|
|
|
|
* description="Return information about the upcoming song playback queue.",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/station_id_required"),
|
|
|
|
* @OA\Response(response=200, description="Success",
|
|
|
|
* @OA\JsonContent(type="array",
|
|
|
|
* @OA\Items(ref="#/components/schemas/Api_StationQueueDetailed")
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=404, description="Station not found"),
|
|
|
|
* @OA\Response(response=403, description="Access denied"),
|
|
|
|
* security={{"api_key": {}}}
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* @OA\Get(path="/station/{station_id}/queue/{id}",
|
|
|
|
* operationId="getQueueItem",
|
|
|
|
* tags={"Stations: Queue"},
|
|
|
|
* description="Retrieve details of a single queued item.",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/station_id_required"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="Queue Item ID",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(type="integer", format="int64")
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=200, description="Success",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Api_StationQueueDetailed")
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=404, description="Station or Queue ID not found"),
|
|
|
|
* @OA\Response(response=403, description="Access denied"),
|
|
|
|
* security={{"api_key": {}}}
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* @OA\Delete(path="/station/{station_id}/queue/{id}",
|
|
|
|
* operationId="deleteQueueItem",
|
|
|
|
* tags={"Stations: Queue"},
|
|
|
|
* description="Delete a single queued item.",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/station_id_required"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="Queue Item ID",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(type="integer", format="int64")
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=200, description="Success",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Api_Status")
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=404, description="Station or Queue ID not found"),
|
|
|
|
* @OA\Response(response=403, description="Access denied"),
|
|
|
|
* security={{"api_key": {}}}
|
|
|
|
* )
|
|
|
|
*
|
2021-07-19 05:53:45 +00:00
|
|
|
* @extends AbstractStationApiCrudController<Entity\StationQueue>
|
|
|
|
*/
|
2019-04-14 03:19:24 +00:00
|
|
|
class QueueController extends AbstractStationApiCrudController
|
2018-12-12 09:01:03 +00:00
|
|
|
{
|
2020-08-16 14:54:01 +00:00
|
|
|
protected string $entityClass = Entity\StationQueue::class;
|
2019-12-07 12:19:49 +00:00
|
|
|
protected string $resourceRouteName = 'api:stations:queue:record';
|
2018-12-12 09:01:03 +00:00
|
|
|
|
2019-09-04 18:00:51 +00:00
|
|
|
public function __construct(
|
2021-04-23 05:24:12 +00:00
|
|
|
protected Entity\ApiGenerator\StationQueueApiGenerator $queueApiGenerator,
|
|
|
|
protected Entity\Repository\StationQueueRepository $queueRepo,
|
2021-10-29 06:16:26 +00:00
|
|
|
App\Doctrine\ReloadableEntityManagerInterface $em,
|
2019-09-04 18:00:51 +00:00
|
|
|
Serializer $serializer,
|
|
|
|
ValidatorInterface $validator,
|
|
|
|
) {
|
2018-12-23 23:26:15 +00:00
|
|
|
parent::__construct($em, $serializer, $validator);
|
2018-12-12 09:01:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 19:57:25 +00:00
|
|
|
public function listAction(
|
|
|
|
ServerRequest $request,
|
|
|
|
Response $response
|
|
|
|
): ResponseInterface {
|
2019-09-10 02:30:05 +00:00
|
|
|
$station = $request->getStation();
|
2021-11-14 08:47:18 +00:00
|
|
|
$query = $this->queueRepo->getUnplayedQuery($station);
|
2019-09-10 02:30:05 +00:00
|
|
|
|
2021-02-09 19:57:25 +00:00
|
|
|
return $this->listPaginatedFromQuery(
|
|
|
|
$request,
|
|
|
|
$response,
|
|
|
|
$query
|
|
|
|
);
|
2018-12-12 09:01:03 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 22:19:31 +00:00
|
|
|
/**
|
2021-04-23 22:12:47 +00:00
|
|
|
* @param object $record
|
2020-07-08 07:03:50 +00:00
|
|
|
* @param ServerRequest $request
|
2018-12-23 23:26:15 +00:00
|
|
|
*/
|
2021-04-23 22:12:47 +00:00
|
|
|
protected function viewRecord(object $record, ServerRequest $request): Entity\Api\StationQueueDetailed
|
2018-12-23 23:26:15 +00:00
|
|
|
{
|
|
|
|
if (!($record instanceof $this->entityClass)) {
|
2019-09-04 18:00:51 +00:00
|
|
|
throw new InvalidArgumentException(sprintf('Record must be an instance of %s.', $this->entityClass));
|
2018-12-12 09:01:03 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 20:27:14 +00:00
|
|
|
$router = $request->getRouter();
|
|
|
|
|
2020-08-16 14:54:01 +00:00
|
|
|
/** @var Entity\StationQueue $record */
|
2020-10-19 10:41:15 +00:00
|
|
|
$row = ($this->queueApiGenerator)($record);
|
2020-02-22 20:27:14 +00:00
|
|
|
$row->resolveUrls($router->getBaseUrl());
|
|
|
|
|
|
|
|
$isInternal = ('true' === $request->getParam('internal', 'false'));
|
2018-12-12 09:01:03 +00:00
|
|
|
|
2020-10-19 10:41:15 +00:00
|
|
|
$apiResponse = new Entity\Api\StationQueueDetailed();
|
|
|
|
$apiResponse->fromParentObject($row);
|
|
|
|
|
2021-11-14 11:14:53 +00:00
|
|
|
$apiResponse->sent_to_autodj = $record->getSentToAutodj();
|
|
|
|
$apiResponse->is_played = $record->getIsPlayed();
|
2020-10-19 10:41:15 +00:00
|
|
|
$apiResponse->autodj_custom_uri = $record->getAutodjCustomUri();
|
2021-02-10 00:29:43 +00:00
|
|
|
$apiResponse->log = $record->getLog();
|
2020-10-19 10:41:15 +00:00
|
|
|
|
|
|
|
$apiResponse->links = [
|
2021-07-19 05:53:45 +00:00
|
|
|
'self' => (string)$router->fromHere($this->resourceRouteName, ['id' => $record->getId()], [], !$isInternal),
|
2018-12-23 23:26:15 +00:00
|
|
|
];
|
2018-12-12 09:01:03 +00:00
|
|
|
|
2020-10-19 10:41:15 +00:00
|
|
|
return $apiResponse;
|
2018-12-12 09:01:03 +00:00
|
|
|
}
|
2021-09-05 22:46:33 +00:00
|
|
|
|
|
|
|
public function clearAction(ServerRequest $request, Response $response): ResponseInterface
|
|
|
|
{
|
|
|
|
$station = $request->getStation();
|
|
|
|
$this->queueRepo->clearUpcomingQueue($station);
|
|
|
|
|
|
|
|
return $response->withJson(Entity\Api\Status::deleted());
|
|
|
|
}
|
2018-12-12 09:01:03 +00:00
|
|
|
}
|