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\Artist;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Teapot\StatusCode;
use Uxmp\Core\Api\AbstractApiApplication;
use Uxmp\Core\Api\Lib\ResultItemFactoryInterface;
use Uxmp\Core\Orm\Repository\ArtistRepositoryInterface;
use Uxmp\Core\Orm\Repository\SongRepositoryInterface;
final class ArtistTopSongsApplication extends AbstractApiApplication
{
public function __construct(
private readonly SongRepositoryInterface $songRepository,
private readonly ArtistRepositoryInterface $artistRepository,
private readonly ResultItemFactoryInterface $resultItemFactory
) {
}
protected function run(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
$list = [];
$artistId = (int) ($args['artistId'] ?? 0);
$artist = $this->artistRepository->find($artistId);
if ($artist === null) {
return $response->withStatus(StatusCode::NOT_FOUND);
$result = $this->songRepository->getTopSongsByArtist($artist);
foreach ($result as $song) {
$list[] = $this->resultItemFactory->createSongListItem($song, $song->getAlbum());
return $this->asJson($response, ['items' => $list]);