@@ -18,10 +18,9 @@ class TrackItem:
18
18
Type: int
19
19
"""
20
20
21
-
22
21
@dataclass (frozen = True )
23
- class ArtistListItem :
24
- """Artist data list """
22
+ class ArtistItem :
23
+ """Gets the artist data """
25
24
26
25
name : str
27
26
"""The name of the artist
@@ -34,6 +33,28 @@ class ArtistListItem:
34
33
Type: list[TrackItem]
35
34
"""
36
35
36
+ @dataclass (frozen = True )
37
+ class ArtistList :
38
+ """Artist data list"""
39
+
40
+ artists : list [ArtistItem ]
41
+ """The name of the artist
42
+
43
+ Type: list[ArtistItem]
44
+ """
45
+
46
+ def __init__ (self ):
47
+ super ().__init__ ()
48
+
49
+ def filter (self , name : str ):
50
+
51
+ data = [x for x in self .artists if x .get ('name' ).lower () == name .lower ()]
52
+
53
+ if len (data ) == 0 :
54
+ return None
55
+
56
+ return ArtistItem (data [0 ].get ('name' ), [TrackItem (x , y ) for x , y in data [0 ].get ('tracks' ).items ()])
57
+
37
58
38
59
@dataclass (frozen = True )
39
60
class MusicResponse :
@@ -44,10 +65,10 @@ class MusicResponse:
44
65
45
66
Type: int
46
67
"""
47
- artists : list [ArtistListItem ]
68
+ artists : list [ArtistList ]
48
69
"""Returns the list of artists
49
70
50
- Type: list[ArtistListItem ]
71
+ Type: list[ArtistList ]
51
72
"""
52
73
53
74
@@ -75,8 +96,10 @@ async def get_top_ten(id: str):
75
96
76
97
return MusicResponse (
77
98
json_response .get ('_id' ),
78
- [ArtistListItem (
79
- x .get ('name' ),
80
- [TrackItem (x , y ) for x , y in x .get ('tracks' ).items ()]
81
- ) for x in json_response .get ('artists' )]
99
+ ArtistList (
100
+ [ArtistItem (
101
+ x .get ('name' ),
102
+ [TrackItem (x , y ) for x , y in x .get ('tracks' ).items ()]
103
+ ) for x in json_response .get ('artists' )]
104
+ )
82
105
)
0 commit comments