Added movie page and route handler

This commit is contained in:
2025-02-23 16:06:47 +11:00
parent 725038009a
commit e794024786
3 changed files with 70 additions and 0 deletions

37
handler/movie.go Normal file
View File

@@ -0,0 +1,37 @@
package handler
import (
"net/http"
"projectreshoot/config"
"projectreshoot/tmdb"
"projectreshoot/view/page"
"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
}
page.Movie(movie).Render(r.Context(), w)
},
)
}