Initial commit
This commit is contained in:
commit
02a6dabcfb
62 files changed
+15751
No files matched your search
@@ -0,0 +1,214 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Pin represents a pin
|
||||
type Pin struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Image string `json:"image"`
|
||||
Type string `json:"type"` // "track", "album", "artist", "playlist"
|
||||
Track *Track `json:"track"`
|
||||
Album *Album `json:"album"`
|
||||
Artist *Artist `json:"artist"`
|
||||
Playlist *Playlist `json:"playlist"`
|
||||
Position int `json:"position"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
ExpiresAt string `json:"expires_at"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a Pin from JSON
|
||||
func (p *Pin) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pin := &Pin{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &pin.ID)
|
||||
}
|
||||
if v, ok := raw["title"]; ok {
|
||||
json.Unmarshal(v, &pin.Title)
|
||||
}
|
||||
if v, ok := raw["description"]; ok {
|
||||
json.Unmarshal(v, &pin.Description)
|
||||
}
|
||||
if v, ok := raw["image"]; ok {
|
||||
json.Unmarshal(v, &pin.Image)
|
||||
}
|
||||
if v, ok := raw["type"]; ok {
|
||||
json.Unmarshal(v, &pin.Type)
|
||||
}
|
||||
if v, ok := raw["position"]; ok {
|
||||
json.Unmarshal(v, &pin.Position)
|
||||
}
|
||||
if v, ok := raw["created_at"]; ok {
|
||||
json.Unmarshal(v, &pin.CreatedAt)
|
||||
}
|
||||
if v, ok := raw["expires_at"]; ok {
|
||||
json.Unmarshal(v, &pin.ExpiresAt)
|
||||
}
|
||||
if v, ok := raw["active"]; ok {
|
||||
json.Unmarshal(v, &pin.Active)
|
||||
}
|
||||
|
||||
if v, ok := raw["track"]; ok {
|
||||
var track Track
|
||||
json.Unmarshal(v, &track)
|
||||
pin.Track = &track
|
||||
}
|
||||
if v, ok := raw["album"]; ok {
|
||||
var album Album
|
||||
json.Unmarshal(v, &album)
|
||||
pin.Album = &album
|
||||
}
|
||||
if v, ok := raw["artist"]; ok {
|
||||
var artist Artist
|
||||
json.Unmarshal(v, &artist)
|
||||
pin.Artist = &artist
|
||||
}
|
||||
if v, ok := raw["playlist"]; ok {
|
||||
var playlist Playlist
|
||||
json.Unmarshal(v, &playlist)
|
||||
pin.Playlist = &playlist
|
||||
}
|
||||
|
||||
return pin, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of Pins
|
||||
func (p *Pin) 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 {
|
||||
pin := &Pin{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, pin); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, pin)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PinData represents pin data
|
||||
type PinData struct {
|
||||
BaseModel
|
||||
Pins []Pin `json:"pins"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// PinsList represents a list of pins
|
||||
type PinsList struct {
|
||||
BaseModel
|
||||
Pins []Pin `json:"pins"`
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
// Presaves represents presaves
|
||||
type Presaves struct {
|
||||
BaseModel
|
||||
Presaves []Presave `json:"presaves"`
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
// Presave represents a presave
|
||||
type Presave struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Image string `json:"image"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
Track *Track `json:"track"`
|
||||
Album *Album `json:"album"`
|
||||
Artist *Artist `json:"artist"`
|
||||
Status string `json:"status"` // "pending", "released", "cancelled"
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a Presave from JSON
|
||||
func (p *Presave) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
presave := &Presave{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &presave.ID)
|
||||
}
|
||||
if v, ok := raw["title"]; ok {
|
||||
json.Unmarshal(v, &presave.Title)
|
||||
}
|
||||
if v, ok := raw["description"]; ok {
|
||||
json.Unmarshal(v, &presave.Description)
|
||||
}
|
||||
if v, ok := raw["image"]; ok {
|
||||
json.Unmarshal(v, &presave.Image)
|
||||
}
|
||||
if v, ok := raw["release_date"]; ok {
|
||||
json.Unmarshal(v, &presave.ReleaseDate)
|
||||
}
|
||||
if v, ok := raw["status"]; ok {
|
||||
json.Unmarshal(v, &presave.Status)
|
||||
}
|
||||
if v, ok := raw["created_at"]; ok {
|
||||
json.Unmarshal(v, &presave.CreatedAt)
|
||||
}
|
||||
if v, ok := raw["updated_at"]; ok {
|
||||
json.Unmarshal(v, &presave.UpdatedAt)
|
||||
}
|
||||
|
||||
if v, ok := raw["track"]; ok {
|
||||
var track Track
|
||||
json.Unmarshal(v, &track)
|
||||
presave.Track = &track
|
||||
}
|
||||
if v, ok := raw["album"]; ok {
|
||||
var album Album
|
||||
json.Unmarshal(v, &album)
|
||||
presave.Album = &album
|
||||
}
|
||||
if v, ok := raw["artist"]; ok {
|
||||
var artist Artist
|
||||
json.Unmarshal(v, &artist)
|
||||
presave.Artist = &artist
|
||||
}
|
||||
|
||||
return presave, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of Presaves
|
||||
func (p *Presave) 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 {
|
||||
presave := &Presave{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, presave); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, presave)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in new issue
Block a user