244 lines
6.4 KiB
Go
244 lines
6.4 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// Concert represents a concert
|
|
type Concert struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Date string `json:"date"`
|
|
Time string `json:"time"`
|
|
Venue *ConcertVenue `json:"venue"`
|
|
Location *ConcertLocation `json:"location"`
|
|
MinPrice int `json:"min_price"`
|
|
MaxPrice int `json:"max_price"`
|
|
Currency string `json:"currency"`
|
|
TicketURI string `json:"ticket_uri"`
|
|
ImageURI string `json:"image_uri"`
|
|
Available bool `json:"available"`
|
|
SoldOut bool `json:"sold_out"`
|
|
Artists []Artist `json:"artists"`
|
|
Genres []string `json:"genres"`
|
|
Cashback *ConcertCashback `json:"cashback"`
|
|
Tabs []ConcertTabConfig `json:"tabs"`
|
|
Skeleton *ConcertSkeleton `json:"skeleton"`
|
|
}
|
|
|
|
// DeJSON deserializes a Concert from JSON
|
|
func (c *Concert) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
concert := &Concert{BaseModel: *NewBaseModel(client)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &concert.ID)
|
|
}
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &concert.Title)
|
|
}
|
|
if v, ok := raw["description"]; ok {
|
|
json.Unmarshal(v, &concert.Description)
|
|
}
|
|
if v, ok := raw["date"]; ok {
|
|
json.Unmarshal(v, &concert.Date)
|
|
}
|
|
if v, ok := raw["time"]; ok {
|
|
json.Unmarshal(v, &concert.Time)
|
|
}
|
|
if v, ok := raw["min_price"]; ok {
|
|
json.Unmarshal(v, &concert.MinPrice)
|
|
}
|
|
if v, ok := raw["max_price"]; ok {
|
|
json.Unmarshal(v, &concert.MaxPrice)
|
|
}
|
|
if v, ok := raw["currency"]; ok {
|
|
json.Unmarshal(v, &concert.Currency)
|
|
}
|
|
if v, ok := raw["ticket_uri"]; ok {
|
|
json.Unmarshal(v, &concert.TicketURI)
|
|
}
|
|
if v, ok := raw["image_uri"]; ok {
|
|
json.Unmarshal(v, &concert.ImageURI)
|
|
}
|
|
if v, ok := raw["available"]; ok {
|
|
json.Unmarshal(v, &concert.Available)
|
|
}
|
|
if v, ok := raw["sold_out"]; ok {
|
|
json.Unmarshal(v, &concert.SoldOut)
|
|
}
|
|
if v, ok := raw["genres"]; ok {
|
|
json.Unmarshal(v, &concert.Genres)
|
|
}
|
|
|
|
if v, ok := raw["venue"]; ok {
|
|
var venue ConcertVenue
|
|
json.Unmarshal(v, &venue)
|
|
concert.Venue = &venue
|
|
}
|
|
if v, ok := raw["location"]; ok {
|
|
var location ConcertLocation
|
|
json.Unmarshal(v, &location)
|
|
concert.Location = &location
|
|
}
|
|
if v, ok := raw["artists"]; ok {
|
|
var artists []Artist
|
|
json.Unmarshal(v, &artists)
|
|
concert.Artists = artists
|
|
}
|
|
if v, ok := raw["cashback"]; ok {
|
|
var cashback ConcertCashback
|
|
json.Unmarshal(v, &cashback)
|
|
concert.Cashback = &cashback
|
|
}
|
|
if v, ok := raw["tabs"]; ok {
|
|
var tabs []ConcertTabConfig
|
|
json.Unmarshal(v, &tabs)
|
|
concert.Tabs = tabs
|
|
}
|
|
if v, ok := raw["skeleton"]; ok {
|
|
var skeleton ConcertSkeleton
|
|
json.Unmarshal(v, &skeleton)
|
|
concert.Skeleton = &skeleton
|
|
}
|
|
|
|
return concert, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Concerts
|
|
func (c *Concert) 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 {
|
|
concert := &Concert{BaseModel: *NewBaseModel(client)}
|
|
if err := json.Unmarshal(item, concert); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, concert)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// ConcertVenue represents a concert venue
|
|
type ConcertVenue struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
City string `json:"city"`
|
|
Country string `json:"country"`
|
|
Capacity int `json:"capacity"`
|
|
ImageURI string `json:"image_uri"`
|
|
}
|
|
|
|
// ConcertLocation represents a concert location
|
|
type ConcertLocation struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
City string `json:"city"`
|
|
Country string `json:"country"`
|
|
Timezone string `json:"timezone"`
|
|
Venues []ConcertVenue `json:"venues"`
|
|
}
|
|
|
|
// ConcertLocations represents concert locations
|
|
type ConcertLocations struct {
|
|
BaseModel
|
|
Locations []ConcertLocation `json:"locations"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|
|
|
|
// ConcertFeed represents a concert feed
|
|
type ConcertFeed struct {
|
|
BaseModel
|
|
Concerts []Concert `json:"concerts"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|
|
|
|
// ConcertInfo represents concert info
|
|
type ConcertInfo struct {
|
|
BaseModel
|
|
Concert *Concert `json:"concert"`
|
|
Related []Concert `json:"related"`
|
|
}
|
|
|
|
// ConcertEventInfo represents concert event info
|
|
type ConcertEventInfo struct {
|
|
BaseModel
|
|
EventID string `json:"event_id"`
|
|
EventType string `json:"event_type"`
|
|
Timestamp string `json:"timestamp"`
|
|
Data json.RawMessage `json:"data"`
|
|
}
|
|
|
|
// ConcertDescription represents concert description
|
|
type ConcertDescription struct {
|
|
BaseModel
|
|
Text string `json:"text"`
|
|
HTML string `json:"html"`
|
|
ShortText string `json:"short_text"`
|
|
}
|
|
|
|
// ConcertCashback represents concert cashback
|
|
type ConcertCashback struct {
|
|
BaseModel
|
|
Amount int `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Percent int `json:"percent"`
|
|
Expires string `json:"expires"`
|
|
}
|
|
|
|
// ConcertMinPrice represents concert min price
|
|
type ConcertMinPrice struct {
|
|
BaseModel
|
|
Price int `json:"price"`
|
|
Currency string `json:"currency"`
|
|
}
|
|
|
|
// ConcertTabConfig represents concert tab config
|
|
type ConcertTabConfig struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Type string `json:"type"`
|
|
Active bool `json:"active"`
|
|
Range *ConcertTabRange `json:"range"`
|
|
}
|
|
|
|
// ConcertTabRange represents concert tab range
|
|
type ConcertTabRange struct {
|
|
BaseModel
|
|
From string `json:"from"`
|
|
To string `json:"to"`
|
|
}
|
|
|
|
// ConcertSkeleton represents concert skeleton
|
|
type ConcertSkeleton struct {
|
|
BaseModel
|
|
Blocks []ConcertSkeletonBlock `json:"blocks"`
|
|
}
|
|
|
|
// ConcertSkeletonBlock represents a concert skeleton block
|
|
type ConcertSkeletonBlock struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
Title string `json:"title"`
|
|
Data json.RawMessage `json:"data"`
|
|
}
|