Skip to content

Commit 67f4a85

Browse files
authored
Refactor data structures for improved clarity and consistency (#73)
- Updated GenreMovieList to use a dedicated Genre type for better structure. - Upgraded Go version in go.mod to 1.24 and updated dependencies, including testify to v1.10.0. - Removed redundant fields from GuestSessionRatedMovies, GuestSessionRatedTVShows, and GuestSessionRatedTVEpisodes, replacing them with PaginatedResultsMeta. - Simplified KeywordMovies by using PaginatedResultsMeta instead of individual pagination fields. - Refactored MovieDetails to utilize structured types for genres, production companies, and spoken languages. - Introduced new types for MovieResult and TVShowResult to streamline search and discovery results. - Consolidated translation structures across various types for consistency. - Enhanced TVDetails structure with specific types for created by, last and next episodes, and networks. - Updated all search and trending response types to use PaginatedResultsMeta for pagination. - Added a new types.go file to centralize common data structures used across the application.
1 parent 704f35d commit 67f4a85

20 files changed

+304
-399
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Go
1717
uses: actions/setup-go@v2
1818
with:
19-
go-version: "1.16"
19+
go-version: "1.24"
2020
- name: Check out code
2121
uses: actions/checkout@v2
2222
- name: Install dependencies

account.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ func (c *Client) GetAccountDetails() (*AccountDetails, error) {
4242

4343
// AccountCreatedLists type is a struct for created lists JSON response.
4444
type AccountCreatedLists struct {
45-
Page int64 `json:"page"`
4645
*AccountCreatedListsResults
47-
TotalPages int64 `json:"total_pages"`
48-
TotalResults int64 `json:"total_results"`
46+
PaginatedResultsMeta
4947
}
5048

5149
// GetCreatedLists get all of the lists created by an account.
@@ -75,10 +73,8 @@ func (c *Client) GetCreatedLists(
7573

7674
// AccountFavoriteMovies type is a struct for favorite movies JSON response.
7775
type AccountFavoriteMovies struct {
78-
Page int64 `json:"page"`
7976
*AccountFavoriteMoviesResults
80-
TotalPages int64 `json:"total_pages"`
81-
TotalResults int64 `json:"total_results"`
77+
PaginatedResultsMeta
8278
}
8379

8480
// GetFavoriteMovies get the list of your favorite movies.
@@ -107,10 +103,8 @@ func (c *Client) GetFavoriteMovies(
107103

108104
// AccountFavoriteTVShows type is a struct for favorite tv shows JSON response.
109105
type AccountFavoriteTVShows struct {
110-
Page int64 `json:"page"`
111106
*AccountFavoriteTVShowsResults
112-
TotalPages int64 `json:"total_pages"`
113-
TotalResults int64 `json:"total_results"`
107+
PaginatedResultsMeta
114108
}
115109

116110
// GetFavoriteTVShows get the list of your favorite TV shows.
@@ -233,10 +227,8 @@ func (c *Client) GetRatedTVShows(
233227

234228
// AccountRatedTVEpisodes type is a struct for rated TV episodes JSON response.
235229
type AccountRatedTVEpisodes struct {
236-
Page int64 `json:"page"`
237230
*AccountRatedTVEpisodesResults
238-
TotalPages int64 `json:"total_pages"`
239-
TotalResults int64 `json:"total_results"`
231+
PaginatedResultsMeta
240232
}
241233

242234
// GetRatedTVEpisodes get a list of all the TV episodes you have rated.

changes.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import "fmt"
55
// ChangesMovie type is a struct for movie changes JSON response.
66
type ChangesMovie struct {
77
*ChangesMovieResults
8-
Page int64 `json:"page"`
9-
TotalPages int64 `json:"total_pages"`
10-
TotalResults int64 `json:"total_results"`
8+
PaginatedResultsMeta
119
}
1210

1311
// GetChangesMovie get a list of all of the movie ids

collections.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,8 @@ func (c *Client) GetCollectionImages(
8585

8686
// CollectionTranslations type is a struct for translations JSON response.
8787
type CollectionTranslations struct {
88-
ID int64 `json:"id"`
89-
Translations []struct {
90-
Iso3166_1 string `json:"iso_3166_1"`
91-
Iso639_1 string `json:"iso_639_1"`
92-
Name string `json:"name"`
93-
EnglishName string `json:"english_name"`
94-
Data struct {
95-
Title string `json:"title"`
96-
Overview string `json:"overview"`
97-
Homepage string `json:"homepage"`
98-
} `json:"data"`
99-
} `json:"translations"`
88+
ID int64 `json:"id"`
89+
Translations []Translation `json:"translations"`
10090
}
10191

10292
// GetCollectionTranslations get the list translations for a collection by id.

credits.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ type CreditsDetails struct {
3737
SeasonNumber int `json:"season_number"`
3838
StillPath string `json:"still_path"`
3939
} `json:"episodes,omitempty"` // TV
40-
Seasons []struct {
41-
AirDate string `json:"air_date"`
42-
EpisodeCount int `json:"episode_count"`
43-
ID int64 `json:"id"`
44-
Name string `json:"name"`
45-
Overview string `json:"overview"`
46-
PosterPath string `json:"poster_path"`
47-
SeasonNumber int `json:"season_number"`
48-
ShowID int64 `json:"show_id"`
49-
} `json:"seasons,omitempty"` // TV
40+
Seasons []Season `json:"seasons,omitempty"` // TV
5041
} `json:"media"`
5142
MediaType string `json:"media_type"`
5243
ID string `json:"id"`

discover.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import "fmt"
44

55
// DiscoverMovie type is a struct for movie JSON response.
66
type DiscoverMovie struct {
7-
Page int64 `json:"page"`
8-
TotalResults int64 `json:"total_results"`
9-
TotalPages int64 `json:"total_pages"`
7+
PaginatedResultsMeta
108
*DiscoverMovieResults
119
}
1210

@@ -54,9 +52,7 @@ func (c *Client) GetDiscoverMovie(
5452

5553
// DiscoverTV type is a struct for tv JSON response.
5654
type DiscoverTV struct {
57-
Page int64 `json:"page"`
58-
TotalResults int64 `json:"total_results"`
59-
TotalPages int64 `json:"total_pages"`
55+
PaginatedResultsMeta
6056
*DiscoverTVResults
6157
}
6258

genres.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import "fmt"
44

55
// GenreMovieList type is a struct for genres movie list JSON response.
66
type GenreMovieList struct {
7-
Genres []struct {
8-
ID int64 `json:"id"`
9-
Name string `json:"name"`
10-
} `json:"genres"`
7+
Genres []Genre `json:"genres"`
118
}
129

1310
// GetGenreMovieList get the list of official genres for movies.

go.mod

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
module github.com/cyruzin/golang-tmdb
22

3-
go 1.13
3+
go 1.24
44

55
require (
66
github.com/json-iterator/go v1.1.12
7-
github.com/stretchr/testify v1.7.1
7+
github.com/stretchr/testify v1.10.0
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
13+
github.com/modern-go/reflect2 v1.0.2 // indirect
14+
github.com/pmezard/go-difflib v1.0.0 // indirect
815
gopkg.in/yaml.v3 v3.0.1 // indirect
916
)

go.sum

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,18 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
44
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
55
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
66
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
7-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
87
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
8+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
9+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
910
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
1011
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
1112
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1213
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
1414
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1515
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
16-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
17-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
19-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
16+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
17+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2018
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2119
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
23-
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo=
24-
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2520
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2621
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

guest_sessions.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import "fmt"
44

55
// GuestSessionRatedMovies type is a struct for rated movies JSON response.
66
type GuestSessionRatedMovies struct {
7-
Page int64 `json:"page"`
87
Results []struct {
98
Adult bool `json:"adult"`
109
BackdropPath string `json:"backdrop_path"`
@@ -22,8 +21,7 @@ type GuestSessionRatedMovies struct {
2221
VoteCount int64 `json:"vote_count"`
2322
Rating float32 `json:"rating"`
2423
} `json:"results"`
25-
TotalPages int64 `json:"total_pages"`
26-
TotalResults int64 `json:"total_results"`
24+
PaginatedResultsMeta
2725
}
2826

2927
// GetGuestSessionRatedMovies get the rated movies for a guest session.
@@ -51,7 +49,6 @@ func (c *Client) GetGuestSessionRatedMovies(
5149

5250
// GuestSessionRatedTVShows type is a struct for rated tv shows JSON response.
5351
type GuestSessionRatedTVShows struct {
54-
Page int64 `json:"page"`
5552
Results []struct {
5653
BackdropPath string `json:"backdrop_path"`
5754
FirstAirDate string `json:"first_air_date"`
@@ -68,8 +65,7 @@ type GuestSessionRatedTVShows struct {
6865
VoteCount int64 `json:"vote_count"`
6966
Rating float32 `json:"rating"`
7067
} `json:"results"`
71-
TotalPages int64 `json:"total_pages"`
72-
TotalResults int64 `json:"total_results"`
68+
PaginatedResultsMeta
7369
}
7470

7571
// GetGuestSessionRatedTVShows get the rated TV shows for a guest session.
@@ -97,7 +93,6 @@ func (c *Client) GetGuestSessionRatedTVShows(
9793

9894
// GuestSessionRatedTVEpisodes type is a struct for rated tv episodes JSON response.
9995
type GuestSessionRatedTVEpisodes struct {
100-
Page int64 `json:"page"`
10196
Results []struct {
10297
AirDate string `json:"air_date"`
10398
EpisodeNumber int `json:"episode_number"`
@@ -112,8 +107,7 @@ type GuestSessionRatedTVEpisodes struct {
112107
VoteCount int64 `json:"vote_count"`
113108
Rating float32 `json:"rating"`
114109
} `json:"results"`
115-
TotalPages int64 `json:"total_pages"`
116-
TotalResults int64 `json:"total_results"`
110+
PaginatedResultsMeta
117111
}
118112

119113
// GetGuestSessionRatedTVEpisodes get the rated TV episodes for a guest session.

keywords.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func (c *Client) GetKeywordDetails(
3131
// KeywordMovies type is a struct for movies that belong to a keyword JSON response.
3232
type KeywordMovies struct {
3333
ID int64 `json:"id"`
34-
Page int64 `json:"page"`
3534
Results []struct {
3635
Adult bool `json:"adult"`
3736
BackdropPath string `json:"backdrop_path"`
@@ -48,8 +47,7 @@ type KeywordMovies struct {
4847
VoteCount int64 `json:"vote_count"`
4948
Popularity float32 `json:"popularity"`
5049
} `json:"results"`
51-
TotalPages int64 `json:"total_pages"`
52-
TotalResults int64 `json:"total_results"`
50+
PaginatedResultsMeta
5351
}
5452

5553
// GetKeywordMovies get the movies that belong to a keyword.

0 commit comments

Comments
 (0)