All checks were successful
Deploy to K8s / deploy (push) Successful in 8s
- Extract AssembleAdults(ctx) from ServeAdults so HTML and JSON API share one reconcile path. - HTMLHandler gains *api.Handler; ServeAdults loads real data and renders adults.tmpl. - AdultsPageData view model + qrHref/qrHrefAll funcMap (URL-encode /qr params, YYYY-MM→MM/YYYY). - adults.tmpl: full reconcile table, per-cell status classes + cell-unpaid-current, Pay button hrefs, totals row, credits/debts/unmatched sections, filter controls, sheet links. - static/js/filters.js: NFD-normalize name filter + month-range column hiding; future months hidden by default. - TestAdultsPage asserts member name and cell text against fixture data. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package web
|
|
|
|
import (
|
|
"fmt"
|
|
"fuj-management/go/internal/config"
|
|
"fuj-management/go/internal/services/membership"
|
|
"fuj-management/go/internal/web/api"
|
|
"fuj-management/go/internal/web/middleware"
|
|
"io/fs"
|
|
"log/slog"
|
|
"net/http"
|
|
)
|
|
|
|
// BuildInfo carries the linker-injected build metadata.
|
|
type BuildInfo struct {
|
|
Version string
|
|
Commit string
|
|
BuildDate string
|
|
}
|
|
|
|
// Run registers routes and starts the HTTP server on addr.
|
|
func Run(logger *slog.Logger, addr string, build BuildInfo, sources membership.Sources, cfg config.Config) error {
|
|
renderer, err := NewRenderer()
|
|
if err != nil {
|
|
return fmt.Errorf("init templates: %w", err)
|
|
}
|
|
|
|
ah := &api.Handler{
|
|
BuildVersion: build.Version,
|
|
BuildCommit: build.Commit,
|
|
BuildDate: build.BuildDate,
|
|
Sources: sources,
|
|
Config: cfg,
|
|
Logger: logger,
|
|
}
|
|
hh := NewHTMLHandler(renderer, build, ah)
|
|
|
|
staticSubFS, err := fs.Sub(staticFS, "static")
|
|
if err != nil {
|
|
return fmt.Errorf("static subfs: %w", err)
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
// HTML routes
|
|
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, "/adults", http.StatusFound)
|
|
})
|
|
mux.HandleFunc("GET /adults", hh.ServeAdults)
|
|
mux.HandleFunc("GET /juniors", hh.ServeJuniors)
|
|
mux.HandleFunc("GET /payments", hh.ServePayments)
|
|
mux.HandleFunc("GET /sync-bank", hh.ServeSync)
|
|
mux.HandleFunc("GET /flush-cache", hh.ServeFlushCache)
|
|
|
|
// Static files
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServerFS(staticSubFS)))
|
|
|
|
// JSON API routes
|
|
mux.HandleFunc("GET /api/version", ah.ServeVersion)
|
|
mux.HandleFunc("GET /api/adults", ah.ServeAdults)
|
|
mux.HandleFunc("GET /api/juniors", ah.ServeJuniors)
|
|
mux.HandleFunc("GET /api/payments", ah.ServePayments)
|
|
|
|
logger.Info("starting server", "addr", addr)
|
|
return http.ListenAndServe(addr, middleware.RequestTimer(logger, mux))
|
|
}
|