1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Usox\HyperSonic\FeatureSet\V1161\Method; |
6
|
|
|
|
7
|
|
|
use Usox\HyperSonic\Exception\ErrorCodeEnum; |
8
|
|
|
use Usox\HyperSonic\Exception\MethodCallFailedException; |
9
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Contract\AlbumDataProviderInterface; |
10
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface; |
11
|
|
|
use Usox\HyperSonic\Response\ResponderInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Retrieves and transforms data for a single album |
15
|
|
|
* |
16
|
|
|
* This class covers the `getAlbum.view` method |
17
|
|
|
*/ |
18
|
|
|
final class GetAlbumMethod implements V1161MethodInterface |
19
|
|
|
{ |
20
|
3 |
|
public function __construct( |
21
|
|
|
private readonly ResponderFactoryInterface $responderFactory, |
22
|
|
|
) { |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array<string, scalar> $queryParams |
27
|
|
|
* @param array<string, scalar> $args |
28
|
|
|
* |
29
|
|
|
* @throws MethodCallFailedException |
30
|
|
|
*/ |
31
|
2 |
|
public function __invoke( |
32
|
|
|
AlbumDataProviderInterface $albumDataProvider, |
33
|
|
|
array $queryParams, |
34
|
|
|
array $args, |
35
|
|
|
): ResponderInterface { |
36
|
2 |
|
$albumId = (string) ($queryParams['id'] ?? null); |
37
|
|
|
|
38
|
2 |
|
$album = $albumDataProvider->getAlbum($albumId); |
39
|
|
|
|
40
|
2 |
|
if ($album === null) { |
41
|
1 |
|
throw new MethodCallFailedException( |
42
|
|
|
ErrorCodeEnum::NOT_FOUND |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
return $this->responderFactory->createAlbumResponder( |
47
|
|
|
[ |
48
|
1 |
|
'id' => $album['id'], |
49
|
1 |
|
'name' => $album['name'], |
50
|
1 |
|
'coverArt' => $album['coverArtId'], |
51
|
1 |
|
'songCount' => $album['songCount'], |
52
|
1 |
|
'created' => $album['createDate']->format(DATE_ATOM), |
53
|
1 |
|
'duration' => $album['duration'], |
54
|
1 |
|
'artist' => $album['artistName'], |
55
|
1 |
|
'artistId' => $album['artistId'], |
56
|
|
|
], |
57
|
1 |
|
array_values( |
58
|
1 |
|
array_map( |
59
|
1 |
|
function (array $song): array { |
60
|
|
|
return [ |
61
|
1 |
|
'id' => $song['id'], |
62
|
1 |
|
'isDir' => $song['isDir'], |
63
|
1 |
|
'title' => $song['name'], |
64
|
1 |
|
'album' => $song['albumName'], |
65
|
1 |
|
'artist' => $song['artistName'], |
66
|
1 |
|
'track' => $song['trackNumber'], |
67
|
1 |
|
'coverArt' => $song['coverArtId'], |
68
|
1 |
|
'size' => $song['size'], |
69
|
1 |
|
'contentType' => $song['contentType'], |
70
|
1 |
|
'duration' => $song['duration'], |
71
|
1 |
|
'created' => $song['createDate']->format(DATE_ATOM), |
72
|
1 |
|
'albumId' => $song['albumId'], |
73
|
1 |
|
'artistId' => $song['artistId'], |
74
|
1 |
|
'playCount' => $song['playCount'], |
75
|
|
|
]; |
76
|
|
|
}, |
77
|
1 |
|
$album['songs'] |
78
|
|
|
) |
79
|
|
|
) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|