|
12 | 12 | from mashumaro.types import Discriminator, SerializationStrategy |
13 | 13 |
|
14 | 14 |
|
| 15 | +class LowercaseAlbumTypeSerializationStrategy(SerializationStrategy): |
| 16 | + """Serialization strategy for objects encapsulated in items.""" |
| 17 | + |
| 18 | + def serialize(self, value: AlbumType) -> str: |
| 19 | + """Serialize optional string.""" |
| 20 | + return value |
| 21 | + |
| 22 | + def deserialize(self, value: str) -> AlbumType: |
| 23 | + """Deserialize optional string.""" |
| 24 | + return AlbumType(value.lower()) |
| 25 | + |
| 26 | + |
15 | 27 | class DeviceType(StrEnum): |
16 | 28 | """Device type.""" |
17 | 29 |
|
@@ -73,6 +85,7 @@ class AlbumType(StrEnum): |
73 | 85 | """Album type.""" |
74 | 86 |
|
75 | 87 | ALBUM = "album" |
| 88 | + EP = "ep" |
76 | 89 | SINGLE = "single" |
77 | 90 | COMPILATION = "compilation" |
78 | 91 |
|
@@ -119,7 +132,11 @@ def deserialize(self, value: dict[str, Any]) -> list[Any]: |
119 | 132 | class SimplifiedAlbum(DataClassORJSONMixin): |
120 | 133 | """Album model.""" |
121 | 134 |
|
122 | | - album_type: AlbumType |
| 135 | + album_type: AlbumType = field( |
| 136 | + metadata=field_options( |
| 137 | + serialization_strategy=LowercaseAlbumTypeSerializationStrategy() |
| 138 | + ) |
| 139 | + ) |
123 | 140 | total_tracks: int |
124 | 141 | album_id: str = field(metadata=field_options(alias="id")) |
125 | 142 | images: list[Image] |
@@ -219,6 +236,20 @@ class Artist(SimplifiedArtist): |
219 | 236 | """Artist model.""" |
220 | 237 |
|
221 | 238 |
|
| 239 | +@dataclass |
| 240 | +class TopArtistsResponse(DataClassORJSONMixin): |
| 241 | + """Top artists response model.""" |
| 242 | + |
| 243 | + items: list[Artist] |
| 244 | + |
| 245 | + |
| 246 | +@dataclass |
| 247 | +class TopTracksResponse(DataClassORJSONMixin): |
| 248 | + """Top tracks response model.""" |
| 249 | + |
| 250 | + items: list[Track] |
| 251 | + |
| 252 | + |
222 | 253 | @dataclass |
223 | 254 | class SimplifiedTrack(DataClassORJSONMixin): |
224 | 255 | """SimplifiedTrack model.""" |
|
0 commit comments