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)
}
}