mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-27 17:38:51 +05:00
fix(search): force KP for ru language in multi search
- MultiSearch returns KP results when lang starts with ru - No fallback to TMDB for ru; KP errors bubble up
This commit is contained in:
@@ -30,51 +30,60 @@ func (h *SearchHandler) MultiSearch(w http.ResponseWriter, r *http.Request) {
|
|||||||
page := getIntQuery(r, "page", 1)
|
page := getIntQuery(r, "page", 1)
|
||||||
language := GetLanguage(r)
|
language := GetLanguage(r)
|
||||||
|
|
||||||
if services.ShouldUseKinopoisk(language) && h.kpService != nil {
|
if services.ShouldUseKinopoisk(language) {
|
||||||
kpSearch, err := h.kpService.SearchFilms(query, page)
|
if h.kpService == nil {
|
||||||
if err == nil {
|
http.Error(w, "Kinopoisk service is not configured", http.StatusBadGateway)
|
||||||
tmdbResp := services.MapKPSearchToTMDBResponse(kpSearch)
|
return
|
||||||
multiResults := make([]models.MultiSearchResult, 0)
|
}
|
||||||
for _, movie := range tmdbResp.Results {
|
|
||||||
multiResults = append(multiResults, models.MultiSearchResult{
|
|
||||||
ID: movie.ID,
|
|
||||||
MediaType: "movie",
|
|
||||||
Title: movie.Title,
|
|
||||||
OriginalTitle: movie.OriginalTitle,
|
|
||||||
Overview: movie.Overview,
|
|
||||||
PosterPath: movie.PosterPath,
|
|
||||||
BackdropPath: movie.BackdropPath,
|
|
||||||
ReleaseDate: movie.ReleaseDate,
|
|
||||||
VoteAverage: movie.VoteAverage,
|
|
||||||
VoteCount: movie.VoteCount,
|
|
||||||
Popularity: movie.Popularity,
|
|
||||||
Adult: movie.Adult,
|
|
||||||
OriginalLanguage: movie.OriginalLanguage,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
json.NewEncoder(w).Encode(models.APIResponse{
|
|
||||||
Success: true,
|
|
||||||
Data: models.MultiSearchResponse{
|
|
||||||
Page: page,
|
|
||||||
Results: multiResults,
|
|
||||||
TotalPages: tmdbResp.TotalPages,
|
|
||||||
TotalResults: tmdbResp.TotalResults,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
results, err := h.tmdbService.SearchMulti(query, page, language)
|
kpSearch, err := h.kpService.SearchFilms(query, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusBadGateway)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
tmdbResp := services.MapKPSearchToTMDBResponse(kpSearch)
|
||||||
json.NewEncoder(w).Encode(models.APIResponse{
|
multiResults := make([]models.MultiSearchResult, 0)
|
||||||
Success: true,
|
for _, movie := range tmdbResp.Results {
|
||||||
Data: results,
|
multiResults = append(multiResults, models.MultiSearchResult{
|
||||||
})
|
ID: movie.ID,
|
||||||
|
MediaType: "movie",
|
||||||
|
Title: movie.Title,
|
||||||
|
OriginalTitle: movie.OriginalTitle,
|
||||||
|
Overview: movie.Overview,
|
||||||
|
PosterPath: movie.PosterPath,
|
||||||
|
BackdropPath: movie.BackdropPath,
|
||||||
|
ReleaseDate: movie.ReleaseDate,
|
||||||
|
VoteAverage: movie.VoteAverage,
|
||||||
|
VoteCount: movie.VoteCount,
|
||||||
|
Popularity: movie.Popularity,
|
||||||
|
Adult: movie.Adult,
|
||||||
|
OriginalLanguage: movie.OriginalLanguage,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(models.APIResponse{
|
||||||
|
Success: true,
|
||||||
|
Data: models.MultiSearchResponse{
|
||||||
|
Page: page,
|
||||||
|
Results: multiResults,
|
||||||
|
TotalPages: tmdbResp.TotalPages,
|
||||||
|
TotalResults: tmdbResp.TotalResults,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// EN/прочие языки — TMDB
|
||||||
|
results, err := h.tmdbService.SearchMulti(query, page, language)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(models.APIResponse{
|
||||||
|
Success: true,
|
||||||
|
Data: results,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user