Files
website/internal/handlers/catalog.go
tumillanino dad3ec655f the rest
2025-10-28 12:36:37 +11:00

26 lines
644 B
Go

package handlers
import (
"html/template"
"net/http"
"decor-by-hannahs/internal/db"
)
func CatalogHandler(q *db.Queries, tmpl *template.Template) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
svcs, err := q.ListServices(r.Context())
if err != nil {
http.Error(w, "unable to load services", http.StatusInternalServerError)
return
}
type data struct {
Services []db.Service
ActivePage string
}
if err := tmpl.ExecuteTemplate(w, "catalog.tmpl", data{Services: svcs, ActivePage: "catalog"}); err != nil {
http.Error(w, "Failed to render page", http.StatusInternalServerError)
}
}
}