refactor: changed file structure

This commit is contained in:
2025-03-05 20:18:28 +11:00
parent 5c1089e0ce
commit 1d9af44d0a
137 changed files with 4986 additions and 581 deletions

44
internal/handler/movie.go Normal file
View 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)
},
)
}