Add a single pair of admin-only endpoints that supersede the scattered
scan-settings JSON routes as the canonical way to read and write
tunable system settings. Existing legacy routes are kept working for
backward compatibility and now refresh the registry cache on write.
system_settings.go:
- GET /api/system/settings returns every known setting with full
metadata (value, type, min, max, requires_restart, category, group,
description, is_default) via SettingsRegistry.All().
- PUT /api/system/settings accepts {key, value}; ApplySetting() looks
up the compiled Default for the key, runs type-aware validation
(int range, bool parse, non-empty string, timezone via
time.LoadLocation), upserts via UpsertSystemSetting, reloads the
registry, and reports whether a restart is needed for the change to
take full effect. Shared by the JSON endpoint and the HTMX endpoint.
- Legacy UpdateScanSettings / GetScanSettings / UpdateTimezoneSettings
now reload the registry after writing and prefer the registry when
reading, so the cache stays consistent regardless of entry point.
sidecar.go:
- SidecarHandler gains an optional registry; the timezone branch of
UpdateSystemConfiguration (PUT /api/system/config) calls
settings.Reload() after the write so the new value is visible
immediately. base_url handling is unchanged.
system.go:
- Register GET/PUT /api/system/settings under the existing admin
/api/system group.
27 lines
814 B
Go
27 lines
814 B
Go
package router
|
|
|
|
import (
|
|
"bookhoard/internal/handlers"
|
|
)
|
|
|
|
func registerSystemRoutes(cfg *Config) {
|
|
e := cfg.Echo
|
|
|
|
// JWT middleware
|
|
jwtMiddleware := createJWTMiddleware(cfg)
|
|
|
|
// Protected routes (admin-only)
|
|
protected := e.Group("/api", jwtMiddleware)
|
|
system := protected.Group("/system", handlers.AdminMiddleware)
|
|
|
|
// System configuration routes (admin-only)
|
|
system.GET("/config", cfg.SidecarHandler.GetSystemConfiguration)
|
|
system.PUT("/config", cfg.SidecarHandler.UpdateSystemConfiguration)
|
|
|
|
// Unified tunable settings (admin-only). These back the admin UI's
|
|
// editable System Settings sections and supersede the legacy
|
|
// /api/libraries/scan-settings JSON routes.
|
|
system.GET("/settings", cfg.SystemSettingsHandler.GetSettings)
|
|
system.PUT("/settings", cfg.SystemSettingsHandler.UpdateSetting)
|
|
}
|