cake-order-tracker/server/server.go
bronkuu 5f156ab6a0 blocked dates page and warning for special-cake orders
Add blocked_date table (migration 5), model, and store CRUD methods.
Add management page at /blocked with add/delete functionality.
Add nav link 'Terminy zablokowane' with event_busy icon.
Pass blocked dates to order form as JSON data attribute.
On form submit, if the order has special cakes and the date is
blocked, show a confirm() dialog warning the user.
2026-06-15 18:54:48 +02:00

50 lines
1.3 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))
mux.HandleFunc("GET /blocked", server.render(server.blocked))
mux.HandleFunc("POST /blocked", server.render(server.postBlocked))
mux.HandleFunc("POST /blocked/{id}/delete", server.render(server.deleteBlocked))
fs := http.FileServerFS(static)
mux.Handle("GET /static/", fs)
server.Handler = mux
return &server
}