|
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\ArtistDataProviderInterface; |
|
10
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface; |
|
11
|
|
|
use Usox\HyperSonic\Response\ResponderInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Retrieves and transforms data for a single artist |
|
15
|
|
|
* |
|
16
|
|
|
* This class covers the `getArtist.view` method |
|
17
|
|
|
*/ |
|
18
|
|
|
final class GetArtistMethod implements V1161MethodInterface |
|
19
|
|
|
{ |
|
20
|
3 |
|
public function __construct( |
|
21
|
|
|
private readonly ResponderFactoryInterface $responderFactory, |
|
22
|
|
|
) { |
|
23
|
3 |
|
} |
|
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
|
|
|
ArtistDataProviderInterface $artistDataProvider, |
|
33
|
|
|
array $queryParams, |
|
34
|
|
|
array $args, |
|
35
|
|
|
): ResponderInterface { |
|
36
|
2 |
|
$artistId = (string) ($queryParams['id'] ?? null); |
|
37
|
|
|
|
|
38
|
2 |
|
$artist = $artistDataProvider->getArtist($artistId); |
|
39
|
|
|
|
|
40
|
2 |
|
if ($artist === null) { |
|
41
|
1 |
|
throw new MethodCallFailedException( |
|
42
|
1 |
|
ErrorCodeEnum::NOT_FOUND |
|
43
|
1 |
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
return $this->responderFactory->createArtistResponder( |
|
47
|
1 |
|
[ |
|
48
|
1 |
|
'id' => (string) $artist['id'], |
|
49
|
1 |
|
'name' => $artist['name'], |
|
50
|
1 |
|
'coverArt' => $artist['coverArtId'], |
|
51
|
1 |
|
'artistImageUrl' => $artist['artistImageUrl'], |
|
52
|
1 |
|
'albumCount' => $artist['albumCount'], |
|
53
|
1 |
|
], |
|
54
|
1 |
|
array_map( |
|
55
|
1 |
|
static fn (array $album): array => [ |
|
56
|
1 |
|
'id' => (string) $album['id'], |
|
57
|
1 |
|
'name' => $album['name'], |
|
58
|
1 |
|
'artist' => $album['artistName'], |
|
59
|
1 |
|
'artistId' => (string) $album['artistId'], |
|
60
|
1 |
|
'coverArt' => $album['coverArtId'], |
|
61
|
1 |
|
'songCount' => $album['songCount'], |
|
62
|
1 |
|
'duration' => $album['duration'], |
|
63
|
1 |
|
'playCount' => $album['playCount'] ?? 0, |
|
64
|
1 |
|
'created' => (string) $album['createDate']?->format(DATE_ATOM), |
|
65
|
1 |
|
'year' => $album['year'] ?? '', |
|
66
|
1 |
|
'genre' => $album['genre'] ?? '', |
|
67
|
1 |
|
], |
|
68
|
1 |
|
$artist['albums'] |
|
69
|
1 |
|
) |
|
70
|
1 |
|
); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|