|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Api\Album; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
9
|
|
|
use Uxmp\Core\Api\AbstractApiApplication; |
|
10
|
|
|
use Uxmp\Core\Component\Config\ConfigProviderInterface; |
|
11
|
|
|
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface; |
|
12
|
|
|
|
|
13
|
|
|
final class AlbumRecentApplication extends AbstractApiApplication |
|
14
|
|
|
{ |
|
15
|
|
|
private const ALBUM_LIMIT = 10; |
|
16
|
|
|
|
|
17
|
1 |
|
public function __construct( |
|
18
|
|
|
private AlbumRepositoryInterface $albumRepository, |
|
19
|
|
|
private ConfigProviderInterface $config |
|
20
|
|
|
) { |
|
21
|
1 |
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
protected function run( |
|
24
|
|
|
ServerRequestInterface $request, |
|
25
|
|
|
ResponseInterface $response, |
|
26
|
|
|
array $args |
|
27
|
|
|
): ResponseInterface { |
|
28
|
1 |
|
$baseUrl = $this->config->getBaseUrl(); |
|
29
|
1 |
|
$list = []; |
|
30
|
|
|
|
|
31
|
1 |
|
foreach ($this->albumRepository->findBy([], ['last_modified' => 'DESC'], static::ALBUM_LIMIT) as $album) { |
|
32
|
1 |
|
$artist = $album->getArtist(); |
|
33
|
|
|
|
|
34
|
|
|
$list[] = [ |
|
35
|
1 |
|
'id' => $album->getId(), |
|
36
|
1 |
|
'artistId' => $artist->getId(), |
|
37
|
1 |
|
'artistName' => $artist->getTitle(), |
|
38
|
1 |
|
'name' => $album->getTitle(), |
|
39
|
1 |
|
'cover' => sprintf('%s/art/album/%s', $baseUrl, $album->getMbid()), |
|
40
|
1 |
|
'length' => $album->getLength(), |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
return $this->asJson($response, ['items' => $list]); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|