update to new webserver module

This commit is contained in:
2026-01-10 14:46:49 +11:00
parent 28b7ba34f0
commit a0cd269466
14 changed files with 199 additions and 69 deletions

View File

@@ -6,36 +6,53 @@ import (
"projectreshoot/internal/view/page"
"strconv"
"git.haelnorr.com/h/golib/hlog"
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/golib/tmdb"
)
func Movie(
server *hws.Server,
config *config.Config,
logger *hlog.Logger,
) 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")
err := server.ThrowError(w, r, hws.HWSError{
StatusCode: http.StatusBadRequest,
Message: "Movie ID provided is not valid",
Error: err,
Level: hws.ErrorDEBUG,
RenderErrorPage: true,
})
if err != nil {
server.ThrowFatal(w, err)
}
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")
err := server.ThrowError(w, r, hws.HWSError{
StatusCode: http.StatusInternalServerError,
Message: "An error occured when trying to retrieve the requested movie",
Error: err,
})
if err != nil {
server.ThrowFatal(w, err)
}
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")
err := server.ThrowError(w, r, hws.HWSError{
StatusCode: http.StatusInternalServerError,
Message: "An error occured when trying to retrieve the credits for the requested movie",
Error: err,
})
if err != nil {
server.ThrowFatal(w, err)
}
return
}
page.Movie(movie, credits, &config.TMDBConfig.Image).Render(r.Context(), w)