|
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 Teapot\StatusCode; |
|
10
|
|
|
use Uxmp\Core\Api\AbstractApiApplication; |
|
11
|
|
|
use Uxmp\Core\Component\Config\ConfigProviderInterface; |
|
12
|
|
|
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class AlbumApplication extends AbstractApiApplication |
|
15
|
|
|
{ |
|
16
|
2 |
|
public function __construct( |
|
17
|
|
|
private readonly AlbumRepositoryInterface $albumRepository, |
|
|
|
|
|
|
18
|
|
|
private readonly ConfigProviderInterface $config, |
|
19
|
|
|
) { |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
2 |
|
protected function run( |
|
23
|
|
|
ServerRequestInterface $request, |
|
24
|
|
|
ResponseInterface $response, |
|
25
|
|
|
array $args |
|
26
|
|
|
): ResponseInterface { |
|
27
|
2 |
|
$albumId = (int) ($args['albumId'] ?? 0); |
|
28
|
|
|
|
|
29
|
2 |
|
$album = $this->albumRepository->find($albumId); |
|
30
|
|
|
|
|
31
|
2 |
|
if ($album === null) { |
|
32
|
1 |
|
return $response->withStatus(StatusCode::NOT_FOUND); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
$artist = $album->getArtist(); |
|
36
|
|
|
|
|
37
|
1 |
|
return $this->asJson( |
|
38
|
|
|
$response, |
|
39
|
|
|
[ |
|
40
|
1 |
|
'id' => $albumId, |
|
41
|
1 |
|
'name' => $album->getTitle(), |
|
42
|
1 |
|
'artistId' => $artist->getId(), |
|
43
|
1 |
|
'artistName' => $artist->getTitle(), |
|
44
|
1 |
|
'cover' => sprintf('%s/art/album/%d', $this->config->getBaseUrl(), $albumId), |
|
45
|
1 |
|
'length' => $album->getLength(), |
|
46
|
1 |
|
'mbId' => $album->getMbid(), |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|