mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-12-15 20:16:10 +05:00
Add 'api/v1/tv/top-rated' route'
This commit is contained in:
@@ -124,7 +124,6 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
api.HandleFunc("/movies/popular", movieHandler.Popular).Methods("GET")
|
||||
api.HandleFunc("/movies/top-rated", movieHandler.TopRated).Methods("GET")
|
||||
api.HandleFunc("/movies/upcoming", movieHandler.Upcoming).Methods("GET")
|
||||
api.HandleFunc("/movies/now-playing", movieHandler.NowPlaying).Methods("GET")
|
||||
api.HandleFunc("/movies/{id}", movieHandler.GetByID).Methods("GET")
|
||||
// Unified prefixed routes
|
||||
api.HandleFunc("/movie/{id}", unifiedHandler.GetMovie).Methods("GET")
|
||||
|
||||
1
main.go
1
main.go
@@ -100,7 +100,6 @@ func main() {
|
||||
api.HandleFunc("/movies/popular", movieHandler.Popular).Methods("GET")
|
||||
api.HandleFunc("/movies/top-rated", movieHandler.TopRated).Methods("GET")
|
||||
api.HandleFunc("/movies/upcoming", movieHandler.Upcoming).Methods("GET")
|
||||
api.HandleFunc("/movies/now-playing", movieHandler.NowPlaying).Methods("GET")
|
||||
api.HandleFunc("/movies/{id}", movieHandler.GetByID).Methods("GET")
|
||||
// Unified prefixed routes
|
||||
api.HandleFunc("/movie/{id}", unifiedHandler.GetMovie).Methods("GET")
|
||||
|
||||
@@ -150,24 +150,6 @@ func (h *MovieHandler) Upcoming(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MovieHandler) NowPlaying(w http.ResponseWriter, r *http.Request) {
|
||||
page := getIntQuery(r, "page", 1)
|
||||
language := GetLanguage(r)
|
||||
region := r.URL.Query().Get("region")
|
||||
|
||||
movies, err := h.movieService.GetNowPlaying(page, language, region)
|
||||
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: movies,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MovieHandler) GetRecommendations(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id, err := strconv.Atoi(vars["id"])
|
||||
|
||||
@@ -99,6 +99,9 @@ type KPFilmShort struct {
|
||||
RatingVoteCount int `json:"ratingVoteCount"`
|
||||
PosterUrl string `json:"posterUrl"`
|
||||
PosterUrlPreview string `json:"posterUrlPreview"`
|
||||
CoverUrl string `json:"coverUrl"`
|
||||
LogoUrl string `json:"logoUrl"`
|
||||
RatingAgeLimits string `json:"ratingAgeLimits"`
|
||||
}
|
||||
|
||||
type KPCountry struct {
|
||||
|
||||
@@ -339,6 +339,9 @@ func mapKPFilmShortToMovie(film KPFilmShort) *models.Movie {
|
||||
posterPath = film.PosterUrl
|
||||
}
|
||||
|
||||
// Backdrop path from coverUrl
|
||||
backdropPath := film.CoverUrl
|
||||
|
||||
title := film.NameRu
|
||||
if title == "" {
|
||||
title = film.NameEn
|
||||
@@ -373,6 +376,7 @@ func mapKPFilmShortToMovie(film KPFilmShort) *models.Movie {
|
||||
OriginalTitle: originalTitle,
|
||||
Overview: film.Description,
|
||||
PosterPath: posterPath,
|
||||
BackdropPath: backdropPath,
|
||||
ReleaseDate: releaseDate,
|
||||
VoteAverage: rating,
|
||||
VoteCount: film.RatingVoteCount,
|
||||
@@ -430,18 +434,18 @@ func mapKPFilmShortToTVShow(film KPFilmShort) *models.TVShow {
|
||||
}
|
||||
|
||||
return &models.TVShow{
|
||||
ID: id,
|
||||
Name: title,
|
||||
OriginalName: originalTitle,
|
||||
Overview: film.Description,
|
||||
PosterPath: posterPath,
|
||||
FirstAirDate: releaseDate,
|
||||
VoteAverage: rating,
|
||||
VoteCount: film.RatingVoteCount,
|
||||
Popularity: rating * 100,
|
||||
Genres: genres,
|
||||
KinopoiskID: id,
|
||||
IMDbID: film.ImdbId,
|
||||
ID: id,
|
||||
Name: title,
|
||||
OriginalName: originalTitle,
|
||||
Overview: film.Description,
|
||||
PosterPath: posterPath,
|
||||
FirstAirDate: releaseDate,
|
||||
VoteAverage: rating,
|
||||
VoteCount: film.RatingVoteCount,
|
||||
Popularity: rating * 100,
|
||||
Genres: genres,
|
||||
KinopoiskID: id,
|
||||
IMDbID: film.ImdbId,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +92,6 @@ func (s *MovieService) GetUpcoming(page int, language, region string) (*models.T
|
||||
return s.tmdb.GetUpcomingMovies(page, language, region)
|
||||
}
|
||||
|
||||
func (s *MovieService) GetNowPlaying(page int, language, region string) (*models.TMDBResponse, error) {
|
||||
return s.tmdb.GetNowPlayingMovies(page, language, region)
|
||||
}
|
||||
|
||||
func (s *MovieService) GetRecommendations(id, page int, language string) (*models.TMDBResponse, error) {
|
||||
return s.tmdb.GetMovieRecommendations(id, page, language)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user