From 6b4a8d86ef3c77bc254883beab6a6cb2f89c8581 Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Sun, 11 Feb 2024 09:34:18 -0500 Subject: [PATCH] Add movie queue --- handlers/routes.go | 1 + handlers/templates/pages/queue.html | 38 +++++++++++++++++++++++++ handlers/templates/partials/navbar.html | 5 ++++ handlers/views.go | 37 ++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 handlers/templates/pages/queue.html diff --git a/handlers/routes.go b/handlers/routes.go index 24abc8d9..3dfca45f 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -53,6 +53,7 @@ func (s *Server) routes() { authenticatedViews.HandleFunc("/account/notifications", s.accountNotificationsGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/account/security", s.accountSecurityGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/movies/{movieID}", s.moviesReadGet()).Methods(http.MethodGet) + authenticatedViews.HandleFunc("/queue", s.queueGet()).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.reviewsNewGet()).Methods(http.MethodGet) diff --git a/handlers/templates/pages/queue.html b/handlers/templates/pages/queue.html new file mode 100644 index 00000000..debb9276 --- /dev/null +++ b/handlers/templates/pages/queue.html @@ -0,0 +1,38 @@ +{{ define "style-tags" }} + +{{ end }} + +{{ define "script-tags" }} + +{{ end }} + +{{ define "custom-elements" }} +{{ end }} + +{{ define "content" }} +

Queue

+ + {{ range .Entries }} +
+ Movie poster for {{ .Title }} +
+

{{ .Title }}

+

{{ .Note }}

+
+
+ {{ end }} +{{ end }} + +{{ template "base.html" }} diff --git a/handlers/templates/partials/navbar.html b/handlers/templates/partials/navbar.html index a3f7ed0a..ef92f8ae 100644 --- a/handlers/templates/partials/navbar.html +++ b/handlers/templates/partials/navbar.html @@ -23,6 +23,11 @@ + {{ if .IsAuthenticated }} + + {{ end }} diff --git a/handlers/views.go b/handlers/views.go index d9928005..39329555 100644 --- a/handlers/views.go +++ b/handlers/views.go @@ -504,6 +504,43 @@ func (s Server) accountSecurityGet() http.HandlerFunc { } } +func (s Server) queueGet() http.HandlerFunc { + type entry struct { + Title screenjournal.MediaTitle + PosterPath url.URL + Note string + } + + return func(w http.ResponseWriter, r *http.Request) { + reviews, err := s.getDB(r).ReadReviews() + if err != nil { + log.Printf("failed to read queue: %v", err) + http.Error(w, "Failed to read queue", http.StatusInternalServerError) + return + } + + entries := make([]entry, len(reviews)) + for i, review := range reviews { + entries[i].Title = review.Movie.Title + entries[i].PosterPath = review.Movie.PosterPath + entries[i].Note = "Seems fun!" + } + + if err := renderTemplate(w, "queue.html", struct { + commonProps + Entries []entry + }{ + commonProps: makeCommonProps("Queue", r.Context()), + Entries: entries, + }, template.FuncMap{ + "posterPathToURL": posterPathToURL, + }); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } +} + func relativeWatchDate(t screenjournal.WatchDate) string { daysAgo := int(time.Since(t.Time()).Hours() / 24) weeksAgo := int(daysAgo / 7)