Files
paliad/internal/handlers/handlers.go
m d1909c766e feat: Phase C — Fristenrechner → DB-backed via FristenrechnerService
- Delete internal/calc/deadlines.go/deadline_rules.go/holidays.go (ported to services)
- fristenrechner handler routes through FristenrechnerService when pool present
- Returns 503 with German message when DATABASE_URL unset (page still renders)
- Migration 012: add name_en columns + seed 9 UI-facing proceeding types
- Commit captures cronus's work after session termination
2026-04-16 17:11:02 +02:00

109 lines
4.7 KiB
Go

package handlers
import (
"encoding/json"
"net/http"
"mgit.msbls.de/m/patholo/internal/auth"
"mgit.msbls.de/m/patholo/internal/services"
)
var authClient *auth.Client
// Services bundles the Phase B + C database-backed services. Pass nil if
// DATABASE_URL was unset; the Akten/deadline endpoints will return 503.
type Services struct {
Akte *services.AkteService
Parteien *services.ParteienService
Rules *services.DeadlineRuleService
Calculator *services.DeadlineCalculator
Users *services.UserService
Fristenrechner *services.FristenrechnerService
}
func Register(mux *http.ServeMux, client *auth.Client, giteaAPIToken string, svc *Services) {
authClient = client
giteaToken = giteaAPIToken
if svc != nil {
dbSvc = &dbServices{
akte: svc.Akte,
parteien: svc.Parteien,
rules: svc.Rules,
calc: svc.Calculator,
users: svc.Users,
fristenrechner: svc.Fristenrechner,
}
}
// API endpoints (JSON, public)
mux.HandleFunc("POST /api/login", handleAPILogin)
mux.HandleFunc("POST /api/register", handleAPIRegister)
// Public pages
mux.HandleFunc("GET /login", handleLoginPage)
mux.HandleFunc("GET /logout", handleLogout)
// Static assets (public)
mux.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("dist/assets"))))
// Protected routes
protected := http.NewServeMux()
protected.HandleFunc("GET /{$}", handleIndex)
protected.HandleFunc("GET /tools/kostenrechner", handleKostenrechnerPage)
protected.HandleFunc("POST /api/tools/kostenrechner", handleKostenrechnerAPI)
protected.HandleFunc("GET /tools/fristenrechner", handleFristenrechnerPage)
protected.HandleFunc("POST /api/tools/fristenrechner", handleFristenrechnerAPI)
protected.HandleFunc("GET /api/tools/proceeding-types", handleProceedingTypes)
protected.HandleFunc("GET /downloads", handleDownloadsPage)
protected.HandleFunc("GET /glossar", handleGlossarPage)
protected.HandleFunc("GET /api/glossar", handleGlossarAPI)
protected.HandleFunc("POST /api/glossar/suggest", handleGlossarSuggest)
protected.HandleFunc("GET /files/{filename}", handleFileDownload)
protected.HandleFunc("POST /api/files/refresh", handleFileRefresh)
protected.HandleFunc("GET /links", handleLinksPage)
protected.HandleFunc("GET /api/links", handleLinksAPI)
protected.HandleFunc("POST /api/links/suggest", handleLinkSuggest)
protected.HandleFunc("POST /api/links/feedback", handleLinkFeedback)
protected.HandleFunc("GET /api/links/suggestions/count", handleSuggestionCount)
protected.HandleFunc("GET /tools/gebuehrentabellen", handleGebuehrentabellenPage)
protected.HandleFunc("GET /api/tools/gebuehrentabellen", handleGebuehrentabellenAPI)
protected.HandleFunc("GET /api/tools/gebuehrentabellen/lookup", handleGebuehrentabellenLookup)
protected.HandleFunc("POST /api/tools/gebuehrentabellen/feedback", handleGebuehrentabellenFeedback)
protected.HandleFunc("GET /checklisten", handleChecklistenPage)
protected.HandleFunc("GET /checklisten/{slug}", handleChecklistDetailPage)
protected.HandleFunc("GET /api/checklisten", handleChecklistenAPI)
protected.HandleFunc("GET /api/checklisten/{slug}", handleChecklistAPI)
protected.HandleFunc("POST /api/checklisten/feedback", handleChecklistenFeedback)
protected.HandleFunc("GET /gerichte", handleGerichtePage)
protected.HandleFunc("GET /api/gerichte", handleGerichteAPI)
protected.HandleFunc("POST /api/gerichte/feedback", handleGerichteFeedback)
// Phase B (DB-backed) — return 503 if DATABASE_URL unset.
protected.HandleFunc("GET /api/deadline-rules", handleListDeadlineRules)
protected.HandleFunc("GET /api/proceeding-types-db", handleListProceedingTypesDB)
protected.HandleFunc("POST /api/deadlines/calculate", handleCalculateDeadlines)
protected.HandleFunc("GET /api/akten", handleListAkten)
protected.HandleFunc("POST /api/akten", handleCreateAkte)
protected.HandleFunc("GET /api/akten/{id}", handleGetAkte)
protected.HandleFunc("PATCH /api/akten/{id}", handleUpdateAkte)
protected.HandleFunc("DELETE /api/akten/{id}", handleDeleteAkte)
protected.HandleFunc("GET /api/akten/{id}/parteien", handleListParteien)
protected.HandleFunc("POST /api/akten/{id}/parteien", handleCreatePartei)
protected.HandleFunc("DELETE /api/parteien/{id}", handleDeletePartei)
// Session middleware refreshes tokens; user-id middleware extracts the
// JWT sub claim into the request context for handlers that need it.
mux.Handle("/", client.Middleware(client.WithUserID(protected)))
}
func handleIndex(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "dist/index.html")
}
func writeJSON(w http.ResponseWriter, status int, data any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(data)
}