diff --git a/handlers/routes.go b/handlers/routes.go index c98691f4..86598e23 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -40,8 +40,8 @@ func (s *Server) routes() { views := s.router.PathPrefix("/").Subrouter() views.Use(upgradeToHttps) views.Use(enforceContentSecurityPolicy) - views.HandleFunc("/about", s.aboutGet()).Methods(http.MethodGet) - views.HandleFunc("/login", s.logInGet()).Methods(http.MethodGet) + views.HandleFunc("/about", s.simplePage("templates/pages/about.html")).Methods(http.MethodGet) + views.HandleFunc("/login", s.simplePage("templates/pages/login.html")).Methods(http.MethodGet) views.HandleFunc("/sign-up", s.signUpGet()).Methods(http.MethodGet) views.HandleFunc("/account/password-reset", s.accountPasswordResetGet()).Methods(http.MethodGet) views.HandleFunc("/account/password-reset", s.accountPasswordResetPut()).Methods(http.MethodPut) @@ -75,13 +75,13 @@ func (s *Server) routes() { authenticatedViews.Use(enforceContentSecurityPolicy) authenticatedViews.HandleFunc("/account/change-password", s.accountChangePasswordGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/account/notifications", s.accountNotificationsGet()).Methods(http.MethodGet) - authenticatedViews.HandleFunc("/account/security", s.accountSecurityGet()).Methods(http.MethodGet) + authenticatedViews.HandleFunc("/account/security", s.simplePage("templates/pages/account-security.html")).Methods(http.MethodGet) authenticatedViews.HandleFunc("/activity", s.activityGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/movies/{movieID}", s.moviesReadGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/tv-shows/{tvShowID}", s.tvShowsReadGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/reviews", s.reviewsGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/reviews/by/{username}", s.reviewsGet()).Methods(http.MethodGet) - authenticatedViews.HandleFunc("/reviews/new", s.reviewsNewTitleSearchGet()).Methods(http.MethodGet) + authenticatedViews.HandleFunc("/reviews/new", s.simplePage("templates/pages/reviews-new.html")).Methods(http.MethodGet) authenticatedViews.HandleFunc("/reviews/new/tv/pick-season", s.reviewsNewPickSeasonGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/reviews/new/write", s.reviewsNewWriteReviewGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/reviews/{reviewID}/edit", s.reviewsEditGet()).Methods(http.MethodGet) diff --git a/handlers/views.go b/handlers/views.go index 04dcb24f..f879535d 100644 --- a/handlers/views.go +++ b/handlers/views.go @@ -192,30 +192,12 @@ func (s Server) indexGet() http.HandlerFunc { } } -func (s Server) aboutGet() http.HandlerFunc { +func (s Server) simplePage(templatePath string) http.HandlerFunc { t := template.Must( template.New("base.html"). ParseFS( templatesFS, - append(baseTemplates, "templates/pages/about.html")...)) - return func(w http.ResponseWriter, r *http.Request) { - if err := t.Execute(w, struct { - commonProps - }{ - commonProps: makeCommonProps(r.Context()), - }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } -} - -func (s Server) logInGet() http.HandlerFunc { - t := template.Must( - template.New("base.html"). - ParseFS( - templatesFS, - append(baseTemplates, "templates/pages/login.html")...)) + append(baseTemplates, templatePath)...)) return func(w http.ResponseWriter, r *http.Request) { if err := t.Execute(w, struct { commonProps @@ -630,28 +612,6 @@ func (s Server) reviewsEditGet() http.HandlerFunc { } } -func (s Server) reviewsNewTitleSearchGet() http.HandlerFunc { - t := template.Must( - template.New("base.html"). - Funcs(reviewPageFns). - ParseFS( - templatesFS, - append( - baseTemplates, - "templates/pages/reviews-new.html")...)) - - return func(w http.ResponseWriter, r *http.Request) { - if err := t.Execute(w, struct { - commonProps - }{ - commonProps: makeCommonProps(r.Context()), - }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } -} - func (s Server) reviewsNewPickSeasonGet() http.HandlerFunc { t := template.Must( template.New("base.html"). @@ -1048,24 +1008,6 @@ func (s Server) accountNotificationsGet() http.HandlerFunc { } } -func (s Server) accountSecurityGet() http.HandlerFunc { - t := template.Must( - template.New("base.html").ParseFS( - templatesFS, - append(baseTemplates, "templates/pages/account-security.html")...)) - - return func(w http.ResponseWriter, r *http.Request) { - if err := t.Execute(w, struct { - commonProps - }{ - commonProps: makeCommonProps(r.Context()), - }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } -} - func (s Server) usersGet() http.HandlerFunc { t := template.Must( template.New("base.html").