Files
yandex-music-api-go/internal/models/label.go
T
MrixsandClaude Code 0456ca0665 Add comprehensive godoc documentation to all exported symbols
- Document all exported types, functions, methods, and constants across 52 files
- Add package-level doc comments to client, models, utils, and ynison packages
- Document HTTP method and endpoint path for each API client method
- Document model struct fields and DeJSON/DeList/ToJSON/ToMap methods
- Fix duplicate package doc comment in internal/models/base.go

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-18 08:57:43 +03:00

97 lines
2.4 KiB
Go

// Package models provides data models for the Yandex Music API.
package models
import (
"encoding/json"
)
// Label represents a label from the Yandex Music API.
type Label struct {
BaseModel
ID string `json:"id"`
Name string `json:"name"`
CoverURI string `json:"cover_uri"`
Description string `json:"description"`
Website string `json:"website"`
SocialLinks []SocialLink `json:"social_links"`
Available bool `json:"available"`
Owner *User `json:"owner"`
}
// DeJSON deserializes a Label from JSON data.
func (l *Label) DeJSON(data []byte, client ClientInterface) (Model, error) {
var raw map[string]json.RawMessage
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
label := &Label{BaseModel: *NewBaseModel(client)}
if v, ok := raw["id"]; ok {
json.Unmarshal(v, &label.ID)
}
if v, ok := raw["name"]; ok {
json.Unmarshal(v, &label.Name)
}
if v, ok := raw["cover_uri"]; ok {
json.Unmarshal(v, &label.CoverURI)
}
if v, ok := raw["description"]; ok {
json.Unmarshal(v, &label.Description)
}
if v, ok := raw["website"]; ok {
json.Unmarshal(v, &label.Website)
}
if v, ok := raw["available"]; ok {
json.Unmarshal(v, &label.Available)
}
if v, ok := raw["social_links"]; ok {
var links []SocialLink
json.Unmarshal(v, &links)
label.SocialLinks = links
}
if v, ok := raw["owner"]; ok {
var user User
json.Unmarshal(v, &user)
label.Owner = &user
}
return label, nil
}
// DeList deserializes a list of Labels from JSON data.
func (l *Label) DeList(data []byte, client ClientInterface) ([]Model, error) {
var rawList []json.RawMessage
if err := json.Unmarshal(data, &rawList); err != nil {
return nil, err
}
result := make([]Model, 0, len(rawList))
for _, item := range rawList {
label := &Label{BaseModel: *NewBaseModel(client)}
if err := json.Unmarshal(item, label); err != nil {
continue
}
result = append(result, label)
}
return result, nil
}
// LabelAlbums represents label albums.
type LabelAlbums struct {
BaseModel
Albums []Album `json:"albums"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
// LabelArtists represents label artists.
type LabelArtists struct {
BaseModel
Artists []Artist `json:"artists"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}