feat: more fields for titles and refactored schemas

This commit is contained in:
Iron_Felix 2025-11-16 01:47:11 +03:00
parent 4949a3c25f
commit e18f4a44c3
2 changed files with 101 additions and 41 deletions

View file

@ -34,6 +34,21 @@ const (
// ReleaseSeason Title release season
type ReleaseSeason string
// Studio defines model for Studio.
type Studio struct {
Description *string `json:"description,omitempty"`
Id *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
PosterId *int64 `json:"poster_id,omitempty"`
PosterPath *string `json:"poster_path,omitempty"`
}
// Tag A localized tag: keys are language codes (ISO 639-1), values are tag names
type Tag map[string]string
// Tags Array of localized tags
type Tags = []Tag
// Title defines model for Title.
type Title struct {
EpisodesAired *int32 `json:"episodes_aired,omitempty"`
@ -41,7 +56,7 @@ type Title struct {
EpisodesLen *map[string]float64 `json:"episodes_len,omitempty"`
// Id Unique title ID (primary key)
Id *int64 `json:"id,omitempty"`
Id int64 `json:"id"`
PosterId *int64 `json:"poster_id,omitempty"`
Rating *float64 `json:"rating,omitempty"`
RatingCount *int32 `json:"rating_count,omitempty"`
@ -49,11 +64,13 @@ type Title struct {
// ReleaseSeason Title release season
ReleaseSeason *ReleaseSeason `json:"release_season,omitempty"`
ReleaseYear *int32 `json:"release_year,omitempty"`
StudioId *int64 `json:"studio_id,omitempty"`
StudioName *string `json:"studio_name,omitempty"`
Studio *Studio `json:"studio,omitempty"`
// Tags Array of localized tags
Tags Tags `json:"tags"`
// TitleNames Localized titles. Key = language (ISO 639-1), value = list of names
TitleNames *map[string][]string `json:"title_names,omitempty"`
TitleNames map[string][]string `json:"title_names"`
// TitleStatus Title status
TitleStatus *TitleStatus `json:"title_status,omitempty"`
@ -201,20 +218,20 @@ func (a *Title) UnmarshalJSON(b []byte) error {
delete(object, "release_year")
}
if raw, found := object["studio_id"]; found {
err = json.Unmarshal(raw, &a.StudioId)
if raw, found := object["studio"]; found {
err = json.Unmarshal(raw, &a.Studio)
if err != nil {
return fmt.Errorf("error reading 'studio_id': %w", err)
return fmt.Errorf("error reading 'studio': %w", err)
}
delete(object, "studio_id")
delete(object, "studio")
}
if raw, found := object["studio_name"]; found {
err = json.Unmarshal(raw, &a.StudioName)
if raw, found := object["tags"]; found {
err = json.Unmarshal(raw, &a.Tags)
if err != nil {
return fmt.Errorf("error reading 'studio_name': %w", err)
return fmt.Errorf("error reading 'tags': %w", err)
}
delete(object, "studio_name")
delete(object, "tags")
}
if raw, found := object["title_names"]; found {
@ -273,11 +290,9 @@ func (a Title) MarshalJSON() ([]byte, error) {
}
}
if a.Id != nil {
object["id"], err = json.Marshal(a.Id)
if err != nil {
return nil, fmt.Errorf("error marshaling 'id': %w", err)
}
object["id"], err = json.Marshal(a.Id)
if err != nil {
return nil, fmt.Errorf("error marshaling 'id': %w", err)
}
if a.PosterId != nil {
@ -315,25 +330,21 @@ func (a Title) MarshalJSON() ([]byte, error) {
}
}
if a.StudioId != nil {
object["studio_id"], err = json.Marshal(a.StudioId)
if a.Studio != nil {
object["studio"], err = json.Marshal(a.Studio)
if err != nil {
return nil, fmt.Errorf("error marshaling 'studio_id': %w", err)
return nil, fmt.Errorf("error marshaling 'studio': %w", err)
}
}
if a.StudioName != nil {
object["studio_name"], err = json.Marshal(a.StudioName)
if err != nil {
return nil, fmt.Errorf("error marshaling 'studio_name': %w", err)
}
object["tags"], err = json.Marshal(a.Tags)
if err != nil {
return nil, fmt.Errorf("error marshaling 'tags': %w", err)
}
if a.TitleNames != nil {
object["title_names"], err = json.Marshal(a.TitleNames)
if err != nil {
return nil, fmt.Errorf("error marshaling 'title_names': %w", err)
}
object["title_names"], err = json.Marshal(a.TitleNames)
if err != nil {
return nil, fmt.Errorf("error marshaling 'title_names': %w", err)
}
if a.TitleStatus != nil {