refactor: changed file structure
This commit is contained in:
44
internal/handler/movie.go
Normal file
44
internal/handler/movie.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"projectreshoot/internal/view/page"
|
||||
"projectreshoot/pkg/config"
|
||||
"projectreshoot/pkg/tmdb"
|
||||
"strconv"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
func Movie(
|
||||
logger *zerolog.Logger,
|
||||
config *config.Config,
|
||||
) http.Handler {
|
||||
return http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("movie_id")
|
||||
movie_id, err := strconv.ParseInt(id, 10, 32)
|
||||
if err != nil {
|
||||
ErrorPage(http.StatusNotFound, w, r)
|
||||
logger.Error().Err(err).Str("movie_id", id).
|
||||
Msg("Error occured getting the movie")
|
||||
return
|
||||
}
|
||||
movie, err := tmdb.GetMovie(int32(movie_id), config.TMDBToken)
|
||||
if err != nil {
|
||||
ErrorPage(http.StatusInternalServerError, w, r)
|
||||
logger.Error().Err(err).Int32("movie_id", int32(movie_id)).
|
||||
Msg("Error occured getting the movie")
|
||||
return
|
||||
}
|
||||
credits, err := tmdb.GetCredits(int32(movie_id), config.TMDBToken)
|
||||
if err != nil {
|
||||
ErrorPage(http.StatusInternalServerError, w, r)
|
||||
logger.Error().Err(err).Int32("movie_id", int32(movie_id)).
|
||||
Msg("Error occured getting the movie credits")
|
||||
return
|
||||
}
|
||||
page.Movie(movie, credits, &config.TMDBConfig.Image).Render(r.Context(), w)
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user