cake-order-tracker/server/server.go
bronkuu 5a5372b831 templates, handlers, CSS, JS: special cakes UI, HTMX nav, dashboard overhaul
Special cakes UI: overlay drawer, basket integration, catalogue tag
filter, form parsing, JS save/edit/remove.
HTMX navigation: MainContent component, nav links with hx-get,
handlers return partial on HX-Request.
Dashboard: metrics grid, CakeBreakdown, OrderRow with status select,
CakeCounts/OrderCounts, torty filter, tort badge, results-pane.
Collapsible sidebar: toggle button, localStorage, CSS transitions.
Location field: dropdown replaced with pill toggle.
Inline style cleanup: moved to CSS classes (tag-grid, grow, icon.sm,
header-actions, toggle-group, success-icon, etc.).
Dead CSS removal: pagination, status-chip, badge-pill, login-page.
Helpers: exported CakeTitle/OrderTitle, added tagNames, tagIDsComma,
orderItemsDesc, specialCakeDetail, removed unused helpers.
2026-06-15 18:50:21 +02:00

47 lines
1.1 KiB
Go

package server
import (
"embed"
"net/http"
"github.com/a-h/templ"
"git.bronku.xyz/bronku/cake-order-tracker/store"
)
type fetcher func(r *http.Request) (templ.Component, int, error)
type Server struct {
s *store.Store
http.Handler
}
//go:embed static/*
var static embed.FS
func redirect(path string, code int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path, code)
}
}
func New(store *store.Store) *Server {
var server Server
server.s = store
mux := http.NewServeMux()
mux.HandleFunc("GET /", redirect("/orders", http.StatusSeeOther))
mux.HandleFunc("GET /order/", server.render(server.order))
mux.HandleFunc("GET /orders", server.render(server.orders))
mux.HandleFunc("GET /cake/", server.render(server.cake))
mux.HandleFunc("GET /cakes", server.render(server.cakes))
mux.HandleFunc("POST /order/", server.render(server.postOrder))
mux.HandleFunc("POST /order/{id}/status", server.render(server.updateStatus))
mux.HandleFunc("POST /cake/", server.render(server.postCake))
fs := http.FileServerFS(static)
mux.Handle("GET /static/", fs)
server.Handler = mux
return &server
}