42 lines
910 B
Go
42 lines
910 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"projectreshoot/internal/config"
|
|
"projectreshoot/internal/view/component/search"
|
|
"projectreshoot/internal/view/page"
|
|
|
|
"git.haelnorr.com/h/golib/hlog"
|
|
"git.haelnorr.com/h/golib/tmdb"
|
|
)
|
|
|
|
func SearchMovies(
|
|
config *config.Config,
|
|
logger *hlog.Logger,
|
|
) http.Handler {
|
|
return http.HandlerFunc(
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
r.ParseForm()
|
|
query := r.FormValue("search")
|
|
if query == "" {
|
|
w.WriteHeader(http.StatusOK)
|
|
return
|
|
}
|
|
movies, err := tmdb.SearchMovies(config.TMDBToken, query, false, 1)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
search.MovieResults(movies, &config.TMDBConfig.Image).Render(r.Context(), w)
|
|
},
|
|
)
|
|
}
|
|
|
|
func MoviesPage() http.Handler {
|
|
return http.HandlerFunc(
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
page.Movies().Render(r.Context(), w)
|
|
},
|
|
)
|
|
}
|