the rest
This commit is contained in:
25
internal/handlers/catalog.go
Normal file
25
internal/handlers/catalog.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user