added admin options

This commit is contained in:
tumillanino
2025-10-28 14:19:54 +11:00
parent e88d625130
commit 788b46a5ea
10 changed files with 162 additions and 20 deletions

View File

@@ -4,10 +4,12 @@ import (
"html/template"
"net/http"
ory "github.com/ory/client-go"
"decor-by-hannahs/internal/db"
)
func CatalogHandler(q *db.Queries, tmpl *template.Template) http.HandlerFunc {
func CatalogHandler(q *db.Queries, tmpl *template.Template, oryClient *ory.APIClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
svcs, err := q.ListServices(r.Context())
if err != nil {
@@ -15,10 +17,17 @@ func CatalogHandler(q *db.Queries, tmpl *template.Template) http.HandlerFunc {
return
}
type data struct {
Services []db.Service
ActivePage string
Services []db.Service
ActivePage string
Authenticated bool
OryLoginURL string
}
if err := tmpl.ExecuteTemplate(w, "catalog.tmpl", data{Services: svcs, ActivePage: "catalog"}); err != nil {
if err := tmpl.ExecuteTemplate(w, "catalog.tmpl", data{
Services: svcs,
ActivePage: "catalog",
Authenticated: isAuthenticated(r, oryClient),
OryLoginURL: "/login",
}); err != nil {
http.Error(w, "Failed to render page", http.StatusInternalServerError)
}
}

View File

@@ -7,6 +7,8 @@ import (
"path/filepath"
"sort"
ory "github.com/ory/client-go"
"decor-by-hannahs/internal/db"
)
@@ -15,7 +17,7 @@ type Photo struct {
Caption string
}
func GalleryHandler(q *db.Queries, tmpl *template.Template) http.HandlerFunc {
func GalleryHandler(q *db.Queries, tmpl *template.Template, oryClient *ory.APIClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var photos []Photo
@@ -40,10 +42,17 @@ func GalleryHandler(q *db.Queries, tmpl *template.Template) http.HandlerFunc {
})
type data struct {
Photos []Photo
ActivePage string
Photos []Photo
ActivePage string
Authenticated bool
OryLoginURL string
}
if err := tmpl.ExecuteTemplate(w, "gallery.tmpl", data{Photos: photos, ActivePage: "gallery"}); err != nil {
if err := tmpl.ExecuteTemplate(w, "gallery.tmpl", data{
Photos: photos,
ActivePage: "gallery",
Authenticated: isAuthenticated(r, oryClient),
OryLoginURL: "/login",
}); err != nil {
http.Error(w, "Failed to render page", http.StatusInternalServerError)
}
}