Fix ID fields to accept both JSON strings and numbers
The Yandex Music API returns IDs as both JSON strings and numbers depending on the endpoint. Added JSONID custom type in internal/models/base.go that implements json.Unmarshaler to accept both formats and store as string. Changed ID fields from string to JSONID: - Track.ID, Major.ID, TrackLyricsInfo.ID (track.go) - Album.ID, TrailerInfo.TrackID, TrailerInfo.AlbumID (album.go) Updated example to convert JSONID to string when passing to client methods. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
0456ca0665
commit
5535d2a941
4 files changed
+49
-20
No files matched your search
+16
-16
@@ -8,20 +8,20 @@ import (
|
||||
// Album represents a full album from the Yandex Music API.
|
||||
type Album struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
CoverURI string `json:"cover_uri"`
|
||||
Genre string `json:"genre"`
|
||||
Year int `json:"year"`
|
||||
TrackCount int `json:"track_count"`
|
||||
Available bool `json:"available"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
Artists []Artist `json:"artists"`
|
||||
Labels []Label `json:"labels"`
|
||||
Volumes [][]Track `json:"volumes"`
|
||||
Description string `json:"description"`
|
||||
Meta *AlbumMeta `json:"meta"`
|
||||
Best *Best `json:"best"`
|
||||
ID JSONID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
CoverURI string `json:"cover_uri"`
|
||||
Genre string `json:"genre"`
|
||||
Year int `json:"year"`
|
||||
TrackCount int `json:"track_count"`
|
||||
Available bool `json:"available"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
Artists []Artist `json:"artists"`
|
||||
Labels []Label `json:"labels"`
|
||||
Volumes [][]Track `json:"volumes"`
|
||||
Description string `json:"description"`
|
||||
Meta *AlbumMeta `json:"meta"`
|
||||
Best *Best `json:"best"`
|
||||
// Additional fields
|
||||
Region string `json:"region"`
|
||||
AvailableForPremiumUsers bool `json:"available_for_premium_users"`
|
||||
@@ -226,8 +226,8 @@ type Best struct {
|
||||
type TrailerInfo struct {
|
||||
BaseModel
|
||||
PreviewURI string `json:"preview_uri"`
|
||||
TrackID string `json:"track_id"`
|
||||
AlbumID string `json:"album_id"`
|
||||
TrackID JSONID `json:"track_id"`
|
||||
AlbumID JSONID `json:"album_id"`
|
||||
Duration int `json:"duration"`
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user