fix read query and field mappings
This commit is contained in:
parent
8ca12c8862
commit
f199d4069c
|
@ -24,14 +24,6 @@ func NewTMDB(apikey string) (*TMDB, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (t TMDB) Search(query string) ([]model.Movie, error) {
|
|
||||||
// return []model.Movie{
|
|
||||||
// {Title: "movie1", Year: 2020, Summary: "summary1"},
|
|
||||||
// {Title: "movie2", Year: 2020, Summary: "summary2"},
|
|
||||||
// {Title: "movie3", Year: 2020, Summary: "summary3"},
|
|
||||||
// }, nil
|
|
||||||
//}
|
|
||||||
|
|
||||||
func (t TMDB) Search(query string) ([]model.Movie, error) {
|
func (t TMDB) Search(query string) ([]model.Movie, error) {
|
||||||
results, err := t.c.GetSearchMovies(query, nil)
|
results, err := t.c.GetSearchMovies(query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +42,9 @@ func (t TMDB) Search(query string) ([]model.Movie, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TMDB) GetMovie(id int64) (model.Movie, error) {
|
func (t TMDB) GetMovie(id int64) (model.Movie, error) {
|
||||||
result, err := t.c.GetMovieDetails(int(id), nil)
|
result, err := t.c.GetMovieDetails(int(id), map[string]string{
|
||||||
|
"append_to_response": "credits",
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.Movie{}, err
|
return model.Movie{}, err
|
||||||
}
|
}
|
||||||
|
@ -60,11 +54,21 @@ func (t TMDB) GetMovie(id int64) (model.Movie, error) {
|
||||||
year = release.Year()
|
year = release.Year()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
directors := make([]string, 0)
|
||||||
|
for crew := range result.Credits.Crew {
|
||||||
|
if result.Credits.Crew[crew].Job == "Director" {
|
||||||
|
directors = append(directors, result.Credits.Crew[crew].Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return model.Movie{
|
return model.Movie{
|
||||||
Title: result.Title,
|
Title: result.OriginalTitle,
|
||||||
TMDBID: result.ID,
|
EnglishTitle: result.Title,
|
||||||
Year: year,
|
TMDBID: result.ID,
|
||||||
Summary: result.Overview,
|
IMDBID: result.IMDbID,
|
||||||
|
Year: year,
|
||||||
|
Directors: directors,
|
||||||
|
Summary: result.Overview,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ WHERE id=?`, id)
|
||||||
ID: id,
|
ID: id,
|
||||||
}
|
}
|
||||||
var directors string
|
var directors string
|
||||||
if err := row.Scan(&m.IMDBID, &m.IMDBID, &m.Title, &m.EnglishTitle, &m.Year, &directors, &m.Summary, &m.WatchedOn, &m.Rating, &m.Comment); err != nil {
|
if err := row.Scan(&m.ID, &m.IMDBID, &m.IMDBID, &m.Title, &m.EnglishTitle, &m.Year, &directors, &m.Summary, &m.WatchedOn, &m.Rating, &m.Comment); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
|
||||||
}
|
}
|
||||||
m.Directors = strings.Split(directors, ",")
|
m.Directors = strings.Split(directors, ",")
|
||||||
|
|
Loading…
Reference in New Issue