for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Uxmp\Core\Api\Playlist;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Teapot\StatusCode\Http;
use Uxmp\Core\Api\AbstractApiApplication;
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
use Uxmp\Core\Orm\Repository\PlaylistRepositoryInterface;
/**
* Retrieves a playlist
*/
final class PlaylistRetrieveApplication extends AbstractApiApplication
{
public function __construct(
private readonly PlaylistRepositoryInterface $playlistRepository,
) {
}
protected function run(
ServerRequestInterface $request,
JsonEnabledResponseInterface $response,
array $args
): ResponseInterface {
$playlistId = (int) ($args['playlistId'] ?? 0);
$playlist = $this->playlistRepository->find($playlistId);
if ($playlist === null) {
return $response->withStatus(Http::NOT_FOUND);
return $response->withJson(
[
'id' => $playlist->getId(),
'name' => $playlist->getName(),
]
);